Peter Wilkinson Peter Wilkinson - 1 year ago 93
Java Question

How to scan multiple paths using the @ComponentScan annotation?

I'm using Spring 3.1 and bootstrapping an application using the


The actual start is done with

new AnnotationConfigApplicationContext(MyRootConfigurationClass.class);

This Configuration class is annotated with

public class MyRootConfigurationClass

and this works fine. However I'd like to be more specific about the packages I scan so I tried.

public class MyRootConfigurationClass

However this fails with errors telling me it can't find components specified using the

What is the correct way to do what I'm after?


Answer Source

@ComponentScan uses string array, like this:


When you provide multiple package names in only one string, Spring interprets this as one package name, and thus can't find it.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download