exclude @Component from @ComponentScan

后端 未结 7 1469
暖寄归人
暖寄归人 2020-11-28 04:10

I have a component that I want to exclude from a @ComponentScan in a particular @Configuration:

@Component(\"foo\") class Foo {
...         


        
7条回答
  •  自闭症患者
    2020-11-28 04:27

    I had an issue when using @Configuration, @EnableAutoConfiguration and @ComponentScan while trying to exclude specific configuration classes, the thing is it didn't work!

    Eventually I solved the problem by using @SpringBootApplication, which according to Spring documentation does the same functionality as the three above in one annotation.

    Another Tip is to try first without refining your package scan (without the basePackages filter).

    @SpringBootApplication(exclude= {Foo.class})
    public class MySpringConfiguration {}
    

提交回复
热议问题