Search code examples
ejbwebsphereclassloader

injected resources from ejb-jar disappeared after changing websphere 7 classloader


I'm configuring an ejb module on websphere 7 and I need to set my classloader to PARENT_LAST to make sure I don't get any classloader issues with wrong version of classes. The odd thing is, my ejb @Resource annotation does not inject my resources anymore (which are defined in ejb-jar.xml) when I change my classloader to PARENT_LAST. All my fields annotated with @Resource are null.


Solution

  • I suspect your application contains a JAR that contains the javax.annotation.Resource class. The PARENT_LAST setting is causing the class loader to prefer your Resource class over the one in the JDK, which means the WebSphere Application Server injection engine never sees your Resource annotation. You should remove that JAR from your application.

    If you want to verify, try adding the following logic to your application before the NPE occurs:

    System.out.println(Resource.class.getProtectionDomain().getCodeSource().getLocation());
    

    ...or enable the -verbose:class (Verbose JVM class loading) option in your server JVM.