Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JdbcRepositoriesRegistrar Not honoring nameGenerator Strategy #1598

Closed
DevCam opened this issue Aug 31, 2023 · 1 comment
Closed

JdbcRepositoriesRegistrar Not honoring nameGenerator Strategy #1598

DevCam opened this issue Aug 31, 2023 · 1 comment
Assignees
Labels
status: invalid An issue that we don't feel is valid

Comments

@DevCam
Copy link

DevCam commented Aug 31, 2023

As per spring-projects/spring-boot#37163 I was directed to report the issue here

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

I. e the repository defined in foo

package com.namestrat.demo.foo;

import org.springframework.data.repository.CrudRepository;

public interface ExampleRepository extends CrudRepository<Example, Long> { }

and a repository with the same name but different package bar

package com.namestrat.demo.bar;

import org.springframework.data.repository.CrudRepository;

public interface ExampleRepository extends CrudRepository<DifferentExample, Long> { }

produces:


  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: 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 😞 )

bean naming strategy
Two repos with same name

rather easy to replicate, but here is a sandbox demo:

demo.zip

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Aug 31, 2023
@mp911de mp911de transferred this issue from spring-projects/spring-data-commons Sep 1, 2023
@mp911de mp911de added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged labels Sep 11, 2023
@mp911de mp911de self-assigned this Sep 11, 2023
@mp911de mp911de added for: team-attention An issue we need to discuss as a team to make progress status: invalid An issue that we don't feel is valid and removed type: bug A general bug for: team-attention An issue we need to discuss as a team to make progress labels Sep 13, 2023
@mp911de
Copy link
Member

mp911de commented Sep 13, 2023

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

@mp911de mp911de closed this as not planned Won't fix, can't repro, duplicate, stale Sep 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: invalid An issue that we don't feel is valid
Projects
None yet
Development

No branches or pull requests

3 participants