Reputation: 351
I'm trying to create a application with Java EE and JBoss WildFly. I've integrated Spring Security to handle authentication and i'm using a custom user detail service to lookup user details in the database.
I have my EAO written in EJB module and its being accessed by the userDeailService in web module.
but when i login the following error is shown.
java.lang.LinkageError: loader constraint violation: when resolving interface method "com.company.eao.UserEAO.findByUserName(Ljava/lang/String;)Lorg/springframework/security/core/userdetails/UserDetails;" the class loader (instance of org/jboss/modules/ModuleClassLoader) of the current class, com/company/security/UserDetailServiceWrapper, and the class loader (instance of org/jboss/modules/ModuleClassLoader) for the method's defining class, com/company/eao/UserEAO, have different Class objects for the type org/springframework/security/core/userdetails/UserDetails used in the signature
From the articles i read it seem both EJB module class loader and the web module class loader loads the UserDetail class hens the error occurred.
how can i specify to use one class loader in WildFly or else how to fix this issue.
Thanks in advance.
Upvotes: 0
Views: 1439
Reputation: 1846
you need to make sure that only one version of this library is used by both deployments since these deployments interchange objects whose classes are part of this lib. You could do this by deploying the lib to the server or by creating a wildfly module for this lib. In both cases both of your deployments must declare a dependency to this lib and you should be fine.
The solution mentioned above should work but personally I prefer to only use JDK-classes or classes of a custom library created by your own as data interchange classes. This way you reduce the dependencies of your deployments and you won't come into trouble introducing newer versions of libraries, ... Furthermore, you could package the lib with your war/ear and pass-around your custom data object without problems.
Upvotes: 0