Shrinidhi
Shrinidhi

Reputation: 23

Spring component-scan not scanning jboss server lib directory

I have a jar file (kept in jboss-home/server/default/lib) and a war file (kept in jboss-home/server/default/deploy). The jar file contains a servlet which initializes the spring context. The servlet is initialized from the war file.

The problem is that the @Component (and @Service, etc) annotations in the jar file are not scanned. It gives NoSuchBeanDefinitionException error. I have declared the following in context xml.

<context:component-scan base-package="com.abc.mypack" />

I have also selected "Add directory entries" when building the jar using eclipse.

If I change to xml based configuration, it works. Or, if I move the jar file to WEB-INF/lib of the war file, it works.

Is there a way to scan the jboss server lib directory for components?

I am using spring 3.1 and Jboss AS 6.

Upvotes: 2

Views: 1905

Answers (1)

carlspring
carlspring

Reputation: 32617

Those annotations don't scan libraries. They scan packages, which means that the libraries containing those packages need to be on the classpath.

Most-likely the libraries you're referring to are on different classloaders.

I would suggest packaging the jar within the war's WEB-INF/lib directory.

Upvotes: 2

Related Questions