Exclude subpackages from Spring autowiring?

后端 未结 9 894
傲寒
傲寒 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:44

    It seems you've done this through XML, but if you were working in new Spring best practice, your config would be in Java, and you could exclude them as so:

    @Configuration
    @EnableWebMvc
    @ComponentScan(basePackages = "net.example.tool",
      excludeFilters = {@ComponentScan.Filter(
        type = FilterType.ASSIGNABLE_TYPE,
        value = {JPAConfiguration.class, SecurityConfig.class})
      })
    

提交回复
热议问题