Spring Boot @ComponentScan exclude 不起作用
Spring Boot About 723 words现象
使用了@ComponentScan
的excludeFilters
但不起作用。
示例代码
@ComponentScan(excludeFilters = @Filter(type = FilterType.ASSIGNABLE_TYPE, classes = TestComponent.class))
@SpringBootApplication
public class App {
public static void main(String[] args) {
SpringApplication.run(App.class, args);
}
}
原因
有其他@Configuration
使用@Bean
注入了该对象。
解决
使用@SpringBootApplication
的exclude
属性,移除注入的@Bean
对象。
@ComponentScan(excludeFilters = @Filter(type = FilterType.ASSIGNABLE_TYPE, classes = TestComponent.class))
@SpringBootApplication(exclude = TestConfig.class)
public class App {
public static void main(String[] args) {
SpringApplication.run(App.class, args);
}
}
参考
Views: 2,952 · Posted: 2022-10-19
————        END        ————
Give me a Star, Thanks:)
https://github.com/fendoudebb/LiteNote扫描下方二维码关注公众号和小程序↓↓↓
Loading...