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
Introduce BeanNameGenerator based on fully qualified class name #24114
Comments
Implementing a custom You can register a custom implementation via Does that meet your needs? |
If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed. |
Yes, a custom Maybe this would be a good enhancement for the spring-boot project. They could supply a property to choose a custom BeanNameGenerator... So I would save me the boilerplate code (10 Lines) in my main class. For completness and to help others: This is my current solution: @SpringBootApplication
@ComponentScan(nameGenerator = CustomGenerator.class)
public class App extends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(App.class, args);
}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application
.sources(App.class);
}
public static class CustomGenerator extends AnnotationBeanNameGenerator {
@Override
public String generateBeanName(BeanDefinition definition, BeanDefinitionRegistry registry) {
return definition.getBeanClassName();
}
}
}
|
Great! And... you're welcome. In light of that, I am closing this issue. I also see that you raised spring-projects/spring-boot#19346 requesting special support in Spring Boot. |
@sbrannen Do you think it's worth surfacing a fully-qualified variant similar |
Affects: Version 5
@ComponentScan
will register Beans with a name generated from the class of the component.Problem:
Having two classes with the same name
UserMapper
in different packages will result in anBeanDefinitionStoreException
org.company.dom -> userMapper
org.company.web -> userMapper
Suggestion:
Include the package in the bean name:
org.company.dom.userMapper
org.company.web.userMapper
Why:
I'm forced to duplicate package information in the class name:
org.company.dom; class domUserMapper
org.company.web; class webUserMapper
same giving each Component a package prefixed name:
org.company.dom; @Component("domUserMapper") class userMapper
org.company.web; @Component("webUserMapper") class userMapper
Especially with generated sources like
MapStruct
this is not possible.Or should I write a custom
BeanNamingStrategy
. For this I do not find so much information, so I guess it's not that famous...The text was updated successfully, but these errors were encountered: