aspose file tools*
The moose likes JBoss/WildFly and the fly likes Jboss class loader isolation problem with spring Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » JBoss/WildFly
Bookmark "Jboss class loader isolation problem with spring" Watch "Jboss class loader isolation problem with spring" New topic
Author

Jboss class loader isolation problem with spring

Bobby Anderson
Ranch Hand

Joined: Oct 28, 2008
Posts: 114
I am running spring inside JBoss 4.2.3 and I am trying to update Hibernate to the latest version. I am using jboss class loader isolation to accomplish this (this is the only way to update hibernate in jboss). I also have my entity beans in a jar file at the ear level. My spring stuff is in a war that lives in the ear.

If I deploy just the ear hibernate is updated and all my entities are processed by hibernate and all looks great.

The problem happens when I introduce my war (which is using spring) into the ear. My spring classes cannot find my entity classes. I.E. I get a NoClassDefFound exception.

I am not sure, but I imagine this is because my entities were deployed in a specific class loader by JBoss and Spring is not going to that class loader to look for classes.

Has anyone ever run into this before? Please Help!
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10046
    
163

Billy Newman wrote: I also have my entity beans in a jar file at the ear level.


I guess you mean Hibernate entities? Or are those EJB2.x entity beans? Moving the entities jar file to .ear/lib folder will make it available to all components, including the war in the ear. However, depending on what kind of "entity beans" those are, you might have to do a few more changes. But first try the .ear/lib approach.

[My Blog] [JavaRanch Journal]
Bobby Anderson
Ranch Hand

Joined: Oct 28, 2008
Posts: 114
They are EJB3 entity beans.

My jars which contain the entity beans are in the lib directory of the .ear file and spring still cannot find them

I am using JBoss 4.2.3 does that make a difference?

Here is my jboss-app.xml ( to isolate class loading so I can update hibernate)


And here is my application.xml for my ear


Also as you can see I am using application_1_4.xsd. Since Jboss 4.2.3 is only EE 1,4 I think this is right but maybe not.

Any other ideas? Thanks!
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10046
    
163

Please post the entire exception stacktrace. That might provide a clue. With the jars in the .ear/lib, the classes in those jars will be available to all components in the .ear. It probably is a case of some class being loaded from the .war classloader as well as the top level .ear classloader. JBoss AS-4.2.x (and later) by default enable a separate classloader for the .war component. You can however disable this in JBOSS_HOME/server/< servername>/deploy/jboss-web.deployer/META-INF/jboss-service.xml, set the UseJBossWebLoader to true:



That probably will solve (or rather workaround) the issue.

Since Jboss 4.2.3 is only EE 1,4 I think this is right but maybe not.

Doesn't matter much since it's only used for xml validation and metadata conversion.
Bobby Anderson
Ranch Hand

Joined: Oct 28, 2008
Posts: 114
I can post the stack trace in a while but I am sure that will not solve my problem. The class in question that spring cannot find is my class. com.test.MyEntity. This class lives in a jar file. That jar file lives in the .ear/lib directory. That jar is not placed in the war. So the class is not getting loaded twice. I assume that spring is not looking in the right place for my class.
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10046
    
163

Billy Newman wrote:I assume that spring is not looking in the right place for my class.


May be. But can't say much without looking at the spring config files or the stacktrace.
Bobby Anderson
Ranch Hand

Joined: Oct 28, 2008
Posts: 114
You can however disable this in JBOSS_HOME/server/< servername>/deploy/jboss-web.deployer/META-INF/jboss-service.xml, set the UseJBossWebLoader to true:


I tried that with no luck so I assume my war is not trying to load a class my ear already loaded.

Here is my spring config file:


Not sure what else you are looking for? I will post the stack trace as well
Bobby Anderson
Ranch Hand

Joined: Oct 28, 2008
Posts: 114
here is the exception:
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10046
    
163

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:448)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)


I'm not really sure how spring creates and instantiates the beans. Not sure if it uses the right classloader.

Nothing informative in the logs, so that leaves us with only one other way to figure out what's going on. Edit the run.bat (or run.sh for *nix OS) to pass



as part of the JAVA_OPTS section. This will print out the jar names from which the classes are being loaded. Before starting the server, remember to redirect the output to some file, because the output is going to be too verbose. After the exception occurs, copy that file and "attach" (do not post the contents since it's going to be too much) that to this thread.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Jboss class loader isolation problem with spring