我正在使用 Spring 4.16 和 Java Annotations,我想做一些类似的事情:
@Configuration
@ComponentScan(basePackages = "com.example.business", includeFilters = @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, value = ServiceComponent.class))
@ComponentScan(basePackages = "com.example.business.framework")
public class ServicesBaseConfiguration {
}
显然,它无法编译。但我希望你明白我的意思。我想要多个具有不同包和过滤器的 ComponentScan。
我无法统一这两个 ComponentsScan,因为它不会从框架创建任何组件,但那些用 ServiceComponent 注释的组件除外,对吗?
你知道我该如何解决这个问题吗?提前致谢
创建两个空的内部类并将@ComponentScan
对它们的注释:
@Configuration
@Import({ServicesBaseConfiguration.Filtered.class, ServicesBaseConfiguration.Unfiltered.class})
public class ServicesBaseConfiguration {
@Configuration
@ComponentScan(basePackages = "com.example.business", includeFilters = @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, value = ServiceComponent.class))
public static class Filtered {}
@Configuration
@ComponentScan(basePackages = "com.example.business.framework")
public static class Unfiltered {}
}
那应该有效
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)