I have one abstract configuration:
@Configuration
@EnableJpaRepositories(basePackages = {
"x","y" }, entityManagerFactoryRef = "entityManager", transactionManagerRef = "transactionManager", repositoryBaseClass = BaseRepositoryImpl.class)
@EnableTransactionManagement
@EnableConfigurationProperties({ DataSourceProperties.class })
public abstract class AbstractBaseConfiguration {}
Then its implemented by the concrete Configuration class
@ComponentScan(basePackages = { "x", "z" })
public class BaseConfiguration extends AbstractBaseConfiguration {}
Combined in
@Configuration
@Import({ BaseConfiguration.class, RestConfiguration.class })
@ComponentScan(basePackages = { "x", "z" })
public class RestBaseConfiguration {}
So nested configurations, in the application at the end RestBaseConfiguration is used.
This was working before when using SpringBoot 2.0.X.
Now I upgraded SpringBoot to latest version (2.6.1). Suddenly I get exception:
org.springframework.beans.factory.support.BeanDefinitionOverrideException:
Invalid bean definition with name 'com.example.XRepository' defined in com.example.XRepository defined in @EnableJpaRepositories declared on AbstractBaseConfiguration
Cannot register bean definition JpaRepositoryFactoryBean defined in XRepository defined in @EnableJpaRepositories declared on AbstractBaseConfiguration
There is already JpaRepositoryFactoryBean defined in XRepository defined in @EnableJpaRepositories declared on BaseConfiguration
I guess underlying issue is because beans are being overwritten https://stackoverflow.com/a/53723731/978302.
The question is why? Based on the error message, is EnableJpaRepositories being also proxied for the abstract class and for this reason repositories will be instantiated twice? Or somehow basePackages parameter of the annotation is interfering with the scans and then scan are executed twice..