You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Using spring 3.0.10 with spring-boot-starter-data-jdbc:
When using a FullyQualifiedAnnotationBeanNameGenerator as the bean naming strategy, repository beans are not named correctly (I suspect it uses the AnnotationBeanNameGenerator ? ).
Consider the application:
package com.namestrat.demo;
@SpringBootApplication(nameGenerator = FullyQualifiedAnnotationBeanNameGenerator.class)
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v3.0.10)
2023-08-31T13:18:34.490-05:00 INFO 23161 --- [ main] com.namestrat.demo.DemoApplication : Starting DemoApplication using Java 17 with PID 23161 (/Users/hackcam/Desktop/demo/target/classes started by hackcam in /Users/hackcam/Desktop/demo)
2023-08-31T13:18:34.492-05:00 INFO 23161 --- [ main] com.namestrat.demo.DemoApplication : No active profile set, falling back to 1 default profile: "default"
2023-08-31T13:18:34.637-05:00 INFO 23161 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JDBC repositories in DEFAULT mode.
2023-08-31T13:18:34.660-05:00 WARN 23161 --- [ main] s.c.a.AnnotationConfigApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.support.BeanDefinitionOverrideException: Invalid bean definition with name 'exampleRepository' defined in com.namestrat.demo.foo.ExampleRepository defined in @EnableJdbcRepositories declared on JdbcRepositoriesRegistrar.EnableJdbcRepositoriesConfiguration: Cannot register bean definition [Root bean: class [org.springframework.data.jdbc.repository.support.JdbcRepositoryFactoryBean]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodNames=null; destroyMethodNames=null; defined in com.namestrat.demo.foo.ExampleRepository defined in @EnableJdbcRepositories declared on JdbcRepositoriesRegistrar.EnableJdbcRepositoriesConfiguration] for bean 'exampleRepository' since there is already [Root bean: class [org.springframework.data.jdbc.repository.support.JdbcRepositoryFactoryBean]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodNames=null; destroyMethodNames=null; defined in com.namestrat.demo.bar.ExampleRepository defined in @EnableJdbcRepositories declared on JdbcRepositoriesRegistrar.EnableJdbcRepositoriesConfiguration] bound.
2023-08-31T13:18:34.667-05:00 INFO 23161 --- [ main] .s.b.a.l.ConditionEvaluationReportLogger :
Error starting ApplicationContext. To display the condition evaluation report re-run your application with 'debug' enabled.
2023-08-31T13:18:34.681-05:00 ERROR 23161 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :
***************************
APPLICATION FAILED TO START
***************************
Description:
The bean 'exampleRepository', defined in com.namestrat.demo.foo.ExampleRepository defined in @EnableJdbcRepositories declared on JdbcRepositoriesRegistrar.EnableJdbcRepositoriesConfiguration, could not be registered. A bean with that name has already been defined in com.namestrat.demo.bar.ExampleRepository defined in @EnableJdbcRepositories declared on JdbcRepositoriesRegistrar.EnableJdbcRepositoriesConfiguration and overriding is disabled.
Action:
Consider renaming one of the beans or enabling overriding by setting spring.main.allow-bean-definition-overriding=true
I've tried fiddling around with package/entityScan, different @configuration with customized @EnableJdbcRepositories and such with no avail - I know that I could simply characterize each repository with a different name but it irks me that the program does not behave as I expected.
I'm fairly new to the whole spring / boot data ecosystem, so If this is in fact expected behavior for repository beans feel free to close this issue!
Somewhat related SO questions (some of them rather old 😞 )
Closing as per comment of the original Boot ticket since the Boot config through @SpringBootApplication(nameGenerator) affects only the component scan, not components registered through ImportBeanDefinitionRegistrar
As per spring-projects/spring-boot#37163 I was directed to report the issue here
Using spring
3.0.10
withspring-boot-starter-data-jdbc
:When using a
FullyQualifiedAnnotationBeanNameGenerator
as the bean naming strategy, repository beans are not named correctly (I suspect it uses theAnnotationBeanNameGenerator
? ).Consider the application:
I. e the repository defined in
foo
and a repository with the same name but different package
bar
produces:
I've tried fiddling around with
package/entityScan
, different@configuration
with customized@EnableJdbcRepositories
and such with no avail - I know that I could simply characterize each repository with a different name but it irks me that the program does not behave as I expected.I'm fairly new to the whole spring / boot data ecosystem, so If this is in fact expected behavior for repository beans feel free to close this issue!
Somewhat related SO questions (some of them rather old 😞 )
bean naming strategy
Two repos with same name
rather easy to replicate, but here is a sandbox demo:
demo.zip
The text was updated successfully, but these errors were encountered: