Exclude subpackages from Spring autowiring?

后端 未结 9 946
傲寒
傲寒 2020-12-02 10:00

Is there a simple way to exclude a package / sub-package from autowiring in Spring 3.1?

E.g., if I wanted to include a component scan with a base package of co

9条回答
  •  余生分开走
    2020-12-02 10:49

    For Spring 4 I use the following
    (I am posting it as the question is 4 years old and more people use Spring 4 than Spring 3.1):

    @Configuration
    @ComponentScan(basePackages = "com.example", 
      excludeFilters = @Filter(type=FilterType.REGEX,pattern="com\\.example\\.ignore\\..*")) 
    public class RootConfig {
        // ...
    }
    

提交回复
热议问题