【发布时间】:2021-11-12 09:50:07
【问题描述】:
必须使用 EclipseLink 作为我的 Spring Batch Job 的 JPA 实现,因为 Hibernate 缺少我需要的重要功能。
不幸的是,在用 EclipseLink 交换 Hibernate 后,我在启动批处理 jar 时收到以下错误:
$ java -jar my-batch.jar
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2021-09-17 15:52:38.387 ERROR 15708 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :
***************************
APPLICATION FAILED TO START
***************************
Description:
The bean 'transactionManager', defined in class path resource [org/springframework/batch/core/configuration/annotation/SimpleBatchConfiguration.class], could not be registered. A bean with that name has already been defined in class path resource [path/to/my/EclipseLinkJpaConfiguration.class] and overriding is disabled.
Action:
Consider renaming one of the beans or enabling overriding by setting spring.main.allow-bean-definition-overriding=true
在我当前的 pom.xml 中,你可以看到我的依赖项以及我如何使用 EclipseLink 交换 Hibernate:
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<version>2.3.12.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
<version>2.3.12.RELEASE</version>
<exclusions>
<exclusion>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
</exclusion>
<exclusion>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.batch</groupId>
<artifactId>spring-batch-core</artifactId>
<version>4.2.7.RELEASE>
</dependency>
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>org.eclipse.persistence.jpa</artifactId>
<version>2.7.5</version>
</dependency>
</dependencies>
除此之外,我还添加了EclipseLinkJpaConfiguration,这是在 Spring 中使用 EclipseLink 所必需的:
@Configuration
public class EclipseLinkJpaConfiguration extends JpaBaseConfiguration {
protected EclipseLinkJpaConfiguration(DataSource dataSource,
JpaProperties properties,
ObjectProvider<JtaTransactionManager> jtaTransactionManager) {
super(dataSource, properties, jtaTransactionManager);
}
@Override
protected AbstractJpaVendorAdapter createJpaVendorAdapter() {
return new EclipseLinkJpaVendorAdapter();
}
@Override
protected Map<String, Object> getVendorProperties() {
Map<String, Object> map = new HashMap<>();
map.put(PersistenceUnitProperties.WEAVING, "false");
map.put(PersistenceUnitProperties.LOGGING_LEVEL, SessionLog.FINER_LABEL);
return map;
}
}
我不知道是什么原因造成的。
添加spring.main.allow-bean-definition-overriding=true 显然是一个临时解决方案,但我想解决这个问题。
我会很感激任何帮助!提前致谢
【问题讨论】:
标签: java jpa spring-batch eclipselink