jsc*_*man 7 java spring annotations spring-4
我使用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 {
}
Run Code Online (Sandbox Code Playgroud)
很可惜,它没有编译.但我希望你明白我的观点.我想要多个ComponentScans包含不同的包和过滤器.
我无法统一两个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 {}
}
Run Code Online (Sandbox Code Playgroud)
这应该工作
| 归档时间: |
|
| 查看次数: |
6264 次 |
| 最近记录: |