Component Scan for custom annotation on Interface

前端 未结 3 1515
野趣味
野趣味 2021-01-18 06:32

I have a component scan configuration as this:

   @Configuration
   @ComponentScan(basePackageClasses = {ITest.class},
                  includeFilters = {@C         


        
3条回答
  •  -上瘾入骨i
    2021-01-18 07:04

    Creating a Dummy implementation seems quite hacky to me and all the steps Cemo mentioned require a lot of effort. But extending ClassPathScanningCandidateComponentProvider is the fastest way:

    ClassPathScanningCandidateComponentProvider scanningProvider = new ClassPathScanningCandidateComponentProvider(false) {
        @Override
        protected boolean isCandidateComponent(AnnotatedBeanDefinition beanDefinition) {
            return true;
        }
    };
    

    Now you´re also able to scan for Interfaces with (custom) Annotations with Spring - which also works in Spring Boot fat jar environments, where the fast-classpath-scanner (which is mentioned in this so q&a) could have some limitations.

提交回复
热议问题