I'm using @ComponentScan
multiple places in the test suite for my application. I want to replace the default bean name generation in Spring, so I have made my own generator like this:
public class FullyQualifiedAnnotationBeanNameGenerator extends AnnotationBeanNameGenerator {
protected String buildDefaultBeanName(BeanDefinition definition) {
return definition.getBeanClassName();
}
}
To use the generator, I'm doing this:
@ComponentScan(nameGenerator = FullyQualifiedAnnotationBeanNameGenerator.class)
The problem is, for every @ComponentScan
in my test configuration classes (classes annotated with @Configuration
), I have to repeat nameGenerator = FullyQualifiedAnnotationBeanNameGenerator.class
.
Is it possible for me to tell Spring to always use the FullyQualifiedAnnotationBeanNameGenerator
as a nameGenerator? I want it to be the default one.
Just create you own Annotation like this:
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@ComponentScan(nameGenerator = FullyQualifiedAnnotationBeanNameGenerator.class)
public @interface MyComponentScan{
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With