How to exclude a sub package from Spring component scanning?


Suppose you are using Spring component scanning and you don’t want to scan classes in the sub-package you should use <context:exclude-filter> subtag of <context:component-scan> tag as shown below

<context:component-scan base-package="com.test.ws">
	<context:exclude-filter type="aspectj" expression="com.test.ws.client.*" />
</context:component-scan>

Here we have defined a aspectj pointcut which will exclude all the classes in the sub-package.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s