vect
vect

Reputation: 665

Spring Framework doesn't see cglib on JBoss

My application uses Spring Framework 3.0.5 on JBoss 5.1.0.GA. The framework is provided by the server, that is, framework libraries are placed in server/<servername>/lib directory. The server is managed by third party, so I can't add any library to environment provided by this server. There is a necessity to use cglib in my application. Spring uses it for proxying purposes. cglib isn't in server/<servername>/lib, therefore I've included cglib-2.2.2.jar to my app .war with maven.

The problem is that the following error occures on deploy:

Cannot proxy target class because CGLIB2 is not available. Add CGLIB to the class path or specify proxy interfaces.

I've checked my app .war for cglib and found it in WEB-INF/lib directory. AFAIK all classes in jars located in this directory are in class path as well as classes in jars in server/<servername>/lib. Why Spring can't find cglib?

Upvotes: 1

Views: 1008

Answers (1)

skaffman
skaffman

Reputation: 403551

For the purposes of this question, the JBoss classloader hierarchy can only look "down", i.e. classes loaded by the system classloader cannot see classes in an application's lib directory. So the Spring libraries in the server's lib directory cannot see cglib in your app's lib directory.

Possible solutions, in order of preference:

  1. Get rid of the Spring JARs from the server's lib directory. They shouldn't be there, it's just a bad idea. But you say you can't do this.
  2. Add cglib to the server's lib directory. Not an option for the same reason as above.
  3. Add duplicates of the Spring JARs to your app's lib directory. Make sure they're exactly the same as the server's, or you risk weird class versioning conflicts. This should allow cglib to be resolved.

Option 3 is far from ideal, since duplicating classes between classloaders is a recipe for classloader issues, but it may be your only option.

Upvotes: 3

Related Questions