1
votes

I am currently migrating apps from JBoss 5.1 to JBoss 7.0 EAP server.
I have added a module to JBoss server named - org.springframework for spring dependency jars

<?xml version="1.0" ?>
<module xmlns="urn:jboss:module:1.1" name="org.springframework">

    <resources>
        <resource-root path="spring-core-3.0.5.RELEASE.jar"/>
        <resource-root path="spring-context-3.0.5.RELEASE.jar"/>
        <resource-root path="spring-beans-3.0.5.RELEASE.jar"/>
        <resource-root path="spring-expression-3.0.5.RELEASE.jar"/>
        <resource-root path="spring-web-3.0.5.RELEASE.jar"/>
        <resource-root path="spring-aop-3.0.5.RELEASE.jar"/>
        <resource-root path="spring-asm-3.0.5.RELEASE.jar"/>
        <resource-root path="spring-jdbc-3.0.5.RELEASE.jar"/>
        <resource-root path="spring-tx-3.0.5.RELEASE.jar"/>
        <resource-root path="org.springframework.web.servlet-3.0.0.M3.jar"/>
        <resource-root path="commons-logging-1.1.1.jar"/>
    </resources>

    <dependencies>
         <module name="javax.api"/>     
         <module name="javax.servlet.jsp.api"/>
         <module name="javax.faces.api"/>
    </dependencies>
</module>

I have defined the module dependency in jboss-deployment-structure.xml of the WAR

<jboss-deployment-structure>

   <deployment>

      <dependencies>
         <module name="com.oracle" />
         <module name="org.springframework" />
      </dependencies>

   </deployment>

</jboss-deployment-structure>

The war deployed to server also contains spring-context-3.0.5.RELEASE.jar in its WEB-INF/lib folder

So I think the required jar - spring-context-3.0.5.RELEASE.jar exists in class path. But still I am getting the below error :

04:33:30,496 INFO  [org.springframework.beans.factory.xml.XmlBeanDefinitionReader] (default task-19) Loading XML bean definitions from class path resource [core_services.xml]
04:33:30,507 INFO  [org.springframework.beans.factory.support.DefaultListableBeanFactory] (default task-19) Pre-instantiating singletons in org.springframework.beans.fact
ory.support.DefaultListableBeanFactory@9b765aa: defining beans [LogService,CacheService,PropertyService]; root of factory hierarchy
2017.02.09 04:33:30 ERROR CashViewsPortalServiceImpl(-2): org/springframework/context/support/ClassPathXmlApplicationContext
CallStack=java.lang.NoClassDefFoundError: org/springframework/context/support/ClassPathXmlApplicationContext
        at com.karthik.common.service.Services.getService(Services.java:31)
        at com.karthik.data.service.DataServices.getService(DataServices.java:18)
        at com.karthik.portal.server.PortalServiceImpl.getInitializeInfo(PortalServiceImpl.java:83)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:497)
        at com.google.gwt.user.server.rpc.RPC.invokeAndEncodeResponse(RPC.java:561)
        at com.google.gwt.user.server.rpc.RemoteServiceServlet.processCall(RemoteServiceServlet.java:265)
        at com.google.gwt.user.server.rpc.RemoteServiceServlet.processPost(RemoteServiceServlet.java:305)
        at com.google.gwt.user.server.rpc.AbstractRemoteServiceServlet.doPost(AbstractRemoteServiceServlet.java:62)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
        at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:85)
        at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62)
        at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)
        at org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)
        at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
        at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:131)
        at io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:57)

1) Why do we need add module in Jboss 7 EAP server for class loading even though the jars are bundled in WEB-INF/lib folder of the war deployed on server?
2) How to resolve the above error
?

1
Had to delete my answer because my assumption was incorrect. In fact the class that's not found is in de spring-core-3.0.5.RELEASE.jarand you already defined that. Try to change the spring module in deployment structure to <module name="org.springframework" export="true" />, adding the export attribute. - Omoro
@Omoro. Thanks for helping me. I added <module name="org.springframework" export="true"/> to jboss-deployment-structure.xml but still getting the same error. May I know what difference does export attribute make. - Karthik
I used this for an application that uses spring in JBoss Wildfly. Through maven I set the the scope of the spring dependencies' to provided so that I only use for the application the spring dependencies provided by the spring module in JBoss. Export attribute is used to export dependencies which other modules might need. <module name="org.springframework" export="true"> <imports> <include path="META-INF**" /> <include path="org**" /> </imports> </module> - Omoro
Ok. But I still getting that error even after adding export attribute. How to solve this. - Karthik
Do I need include <imports> tag in jboss-deployment-structure.xml - Karthik

1 Answers

0
votes

I think you have n't defined the spring dependencies perfectly. Below are the steps:

You can define Spring as a module

The following are steps to create a Spring module:

1.Download the desired version of Spring. For this example we are using Spring 3.1.1.

2.Create the directory: $JBOSS_HOME/modules/org/springframework/spring/main.

3.Copy the Spring libraries you downloaded to that directory.

4.Create module.xml with the following contents under that directory. Make sure these correspond to the libraries' names:

<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.1" name="org.springframework.spring">
  <resources>
    <resource-root path="org.springframework.aop-3.1.1.RELEASE.jar"/>
    <resource-root path="org.springframework.asm-3.1.1.RELEASE.jar"/>
    <resource-root path="org.springframework.aspects-3.1.1.RELEASE.jar"/>
    <resource-root path="org.springframework.beans-3.1.1.RELEASE.jar"/>
    <resource-root path="org.springframework.context-3.1.1.RELEASE.jar"/>
    <resource-root path="org.springframework.context.support-3.1.1.RELEASE.jar"/>
    <resource-root path="org.springframework.core-3.1.1.RELEASE.jar"/>
    <resource-root path="org.springframework.expression-3.1.1.RELEASE.jar"/>
    <resource-root path="org.springframework.instrument-3.1.1.RELEASE.jar"/>
    <resource-root path="org.springframework.instrument.tomcat-3.1.1.RELEASE.jar"/>
    <resource-root path="org.springframework.jdbc-3.1.1.RELEASE.jar"/>
    <resource-root path="org.springframework.jms-3.1.1.RELEASE.jar"/>
    <resource-root path="org.springframework.orm-3.1.1.RELEASE.jar"/>
    <resource-root path="org.springframework.oxm-3.1.1.RELEASE.jar"/>
    <resource-root path="org.springframework.test-3.1.1.RELEASE.jar"/>
    <resource-root path="org.springframework.transaction-3.1.1.RELEASE.jar"/>
    <resource-root path="org.springframework.web-3.1.1.RELEASE.jar"/>
    <resource-root path="org.springframework.web.portlet-3.1.1.RELEASE.jar"/>
    <resource-root path="org.springframework.web.servlet-3.1.1.RELEASE.jar"/>
    <resource-root path="org.springframework.web.struts-3.1.1.RELEASE.jar"/>
  </resources>
  <dependencies>
    <module name="org.apache.commons.logging"/>
    <module name="javax.api" export="true"/>
    <module name="org.jboss.vfs"/> 
  </dependencies>
</module>

Here is an absolute minimal module.xml (the different Spring version is irrelevant):

<?xml version="1.0"?>
<module xmlns="urn:jboss:module:1.1" name="org.springframework.spring">
  <resources>
    <resource-root path="spring-aop-3.2.3.RELEASE.jar"/>
    <resource-root path="spring-beans-3.2.3.RELEASE.jar"/>
    <resource-root path="spring-context-3.2.3.RELEASE.jar"/>
    <resource-root path="spring-core-3.2.3.RELEASE.jar"/>
    <resource-root path="spring-expression-3.2.3.RELEASE.jar"/>
  </resources>
  <dependencies>
    <module name="javax.api"/>
    <module name="org.apache.commons.logging"/>
  </dependencies>
</module>

5.Put the following jboss-deployment-structure.xml in your application archive (WEB-INF/jboss-deployment-structure.xml for WAR or META-INF/jboss-deployment-structure.xml for EAR or EJB-jar) to use the above module:

If you're using JBoss EAP 6.1.x and greater or EAP 7, then use below:

<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure>
  <deployment>
    <dependencies>
      <module name="org.springframework.spring" export="true" meta-inf="export"/>
    </dependencies>
  </deployment>
</jboss-deployment-structure>

If JBoss EAP 6.0.x, then use below

<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure>   
  <deployment>
    <dependencies>
      <module name="org.springframework.spring" export="true">
        <imports>
          <include path="META-INF**"/>
          <include path="org**"/>
        </imports>
        <exports>
          <include path="META-INF**"/>
          <include path="org**"/>
        </exports>
      </module>
    </dependencies>
  </deployment>
</jboss-deployment-structure>

Note: The meta-inf on the module in the jboss-deployment-structure.xml was added in JBoss EAP 6.1.0, which allows the files in the META-INF of a resource to be visible. Since this was not available in JBoss EAP 6.0.x, the section allows you to get access to the META-INF directory which is not visible by default.

Note: The Spring Framework module should not include resources such as servlet-api.jar, xml-apis.jar, jta-api.jar, and other APIs. These APIs are implemented by either the JDK or JBoss and trying to use a different version of the API will lead to classloading issues and other problems.

Note: The Spring module should include all of its non Java / JavaEE dependencies. The Spring module can depend on javax.api / javaee.api provided by JBoss and any public JBoss module, but for other dependencies Spring has such as aopalliance, they would need to be included as resources in the module or in another custom module.