2

have to use EclipseLink as JPA implementation for my Spring Batch Job because Hibernate lacks an important feature that I need.

Unfortunately, after exchanging Hibernate with EclipseLink, i get the following error when starting my batch 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

In my current pom.xml u can see my dependencies and how i exchanged Hibernate with EclipseLink:

<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>

In addition to this I added EclipseLinkJpaConfiguration which is required in order to use EclipseLink in Spring:

@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;
    }
}

I have no idea whats causing this. Adding spring.main.allow-bean-definition-overriding=true is obviously a temporary solution but i would like to fix this. I'd appreciate any help! Thanks in advance

Manu
  • 284
  • 2
  • 20

1 Answers1

3

This is a known issue, see https://github.com/spring-projects/spring-batch/issues/816. The fix is planned for version 5.0, planned for Q4 2022.

In the meantime, you can allow bean definition overriding or rename your bean to something other than transactionManager.

Mahmoud Ben Hassine
  • 28,519
  • 3
  • 32
  • 50