I have a component scan configuration as this:
@Configuration
@ComponentScan(basePackageClasses = {ITest.class},
includeFilters = {@ComponentScan.Filter(type = FilterType.ANNOTATION, value = JdbiRepository.class)})
public class MyConfig {
}
Basically I would like to create scan interface which has JdbiRepository
annotation
@JdbiRepository
public interface ITest {
Integer deleteUserSession(String id);
}
And I would like to create proxy implementation of my interfaces. For this purpose I registered a custom SmartInstantiationAwareBeanPostProcessor
which is basically creating necessary instances but the configuration above does not scan interfaces which has JdbiRepository
annotation.
How can I scan interfaces by custom annotation?
Edit:
It seems that org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider#isCandidateComponent
is accepting only concrete classes.
/**
* Determine whether the given bean definition qualifies as candidate.
* <p>The default implementation checks whether the class is concrete
* (i.e. not abstract and not an interface). Can be overridden in subclasses.
* @param beanDefinition the bean definition to check
* @return whether the bean definition qualifies as a candidate component
*/
protected boolean isCandidateComponent(AnnotatedBeanDefinition beanDefinition) {
return (beanDefinition.getMetadata().isConcrete() && beanDefinition.getMetadata().isIndependent());
}
Edit:
@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Component
public @interface JdbiRepository {
/**
* The value may indicate a suggestion for a logical component name,
* to be turned into a Spring bean in case of an autodetected component.
* @return the suggested component name, if any
*/
String value() default "";
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…