我有一个组件扫描配置,如下所示:
@Configuration
@ComponentScan(basePackageClasses = {ITest.class},
includeFilters = {@ComponentScan.Filter(type = FilterType.ANNOTATION, value = JdbiRepository.class)})
public class MyConfig {
}
基本上我想创建带有JdbiRepository
注释的扫描界面
@JdbiRepository
public interface ITest {
Integer deleteUserSession(String id);
}
我想创建我的接口的代理实现。为此,我注册了一个自定义SmartInstantiationAwareBeanPostProcessor
,它基本上是创建必要的实例,但上面的配置不扫描具有JdbiRepository
注释的接口。
如何通过自定义注释扫描接口?
编辑:
似乎org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider#isCandidateComponent
只接受具体的课程。
/**
* 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());
}
编辑:
@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 "";
}