Exclude subpackages from Spring autowiring?

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

    I'm not sure you can exclude packages explicitly with an , but I bet using a regex filter would effectively get you there:

     
        
     
    

    To make it annotation-based, you'd annotate each class you wanted excluded for integration tests with something like @com.example.annotation.ExcludedFromITests. Then the component-scan would look like:

     
        
     
    

    That's clearer because now you've documented in the source code itself that the class is not intended to be included in an application context for integration tests.

提交回复
热议问题