JBOSS EAP 7.0 - java.lang.NoClassDefFoundError:org/springframework/context/support/ClassPathXmlApplicationContext
JBOSS EAP 7.0 - java.lang.NoClassDefFoundError:org/springframework/context/support/ClassPathXmlApplicationContext
我目前正在将应用程序从 JBoss 5.1 迁移到 JBoss 7.0 EAP 服务器。
我已将模块添加到 JBoss 服务器,名为 - 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>
我在WAR
的jboss-deployment-structure.xml中定义了模块依赖
<jboss-deployment-structure>
<deployment>
<dependencies>
<module name="com.oracle" />
<module name="org.springframework" />
</dependencies>
</deployment>
</jboss-deployment-structure>
部署到服务器的 war 还在其 WEB-INF/lib 文件夹中包含 spring-context-3.0.5.RELEASE.jar
所以我认为所需的 jar - spring-context-3.0.5.RELEASE.jar 存在于 class 路径中。但我仍然收到以下错误:
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) 为什么我们需要在 Jboss 7 EAP 服务器中添加模块以进行 class 加载,即使 jars 捆绑在 WEB-INF/lib 文件夹中 war
部署在服务器上?
2) 如何解决上述错误?
我认为你没有完美地定义spring依赖关系。以下是步骤:
您可以将Spring定义为模块
以下是创建 Spring 模块的步骤:
1.Download Spring 的所需版本。对于这个例子,我们使用 Spring 3.1.1.
2.Create目录:$JBOSS_HOME/modules/org/springframework/spring/main.
3.Copy 您下载到该目录的 Spring 个库。
4.Create module.xml 目录下有如下内容。确保这些与库的名称相对应:
<?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>
这是一个绝对最小的module.xml(不同的Spring版本无关):
<?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 以下 jboss-deployment-structure.xml 在您的应用程序存档中(WEB-INF/jboss-deployment-structure.xml for WAR or META-INF/jboss-deployment-structure.xml 对于 EAR 或 EJB-jar) 使用以上模块:
如果您使用的是 JBoss EAP 6.1.x 及更高版本或 EAP 7,请使用以下内容:
<?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>
如果JBoss EAP 6.0.x,则使用下面
<?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>
注意:jboss-deployment-structure.xml模块上的meta-inf是在JBoss EAP 6.1.0中添加的,允许META-INF 的资源是可见的。由于这在 JBoss EAP 6 中不可用。0.x,该部分允许您访问默认情况下不可见的 META-INF 目录。
注意:Spring框架模块不应包含servlet-api.jar、xml-apis.jar、jta-api.jar等资源API秒。这些 API 由 JDK 或 JBoss 实现,尝试使用不同版本的 API 将导致类加载问题和其他问题。
注意:Spring 模块应包含其所有非 Java / JavaEE 依赖项。 Spring 模块可以依赖于 JBoss 提供的 javax.api / javaee.api 和任何 public JBoss 模块,但对于其他依赖项 Spring 有诸如 aopalliance,它们需要作为资源包含在模块或另一个自定义模块中。
我目前正在将应用程序从 JBoss 5.1 迁移到 JBoss 7.0 EAP 服务器。
我已将模块添加到 JBoss 服务器,名为 - 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>
我在WAR
的jboss-deployment-structure.xml中定义了模块依赖<jboss-deployment-structure>
<deployment>
<dependencies>
<module name="com.oracle" />
<module name="org.springframework" />
</dependencies>
</deployment>
</jboss-deployment-structure>
部署到服务器的 war 还在其 WEB-INF/lib 文件夹中包含 spring-context-3.0.5.RELEASE.jar
所以我认为所需的 jar - spring-context-3.0.5.RELEASE.jar 存在于 class 路径中。但我仍然收到以下错误:
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) 为什么我们需要在 Jboss 7 EAP 服务器中添加模块以进行 class 加载,即使 jars 捆绑在 WEB-INF/lib 文件夹中 war
部署在服务器上?
2) 如何解决上述错误?
我认为你没有完美地定义spring依赖关系。以下是步骤:
您可以将Spring定义为模块
以下是创建 Spring 模块的步骤:
1.Download Spring 的所需版本。对于这个例子,我们使用 Spring 3.1.1.
2.Create目录:$JBOSS_HOME/modules/org/springframework/spring/main.
3.Copy 您下载到该目录的 Spring 个库。
4.Create module.xml 目录下有如下内容。确保这些与库的名称相对应:
<?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>
这是一个绝对最小的module.xml(不同的Spring版本无关):
<?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 以下 jboss-deployment-structure.xml 在您的应用程序存档中(WEB-INF/jboss-deployment-structure.xml for WAR or META-INF/jboss-deployment-structure.xml 对于 EAR 或 EJB-jar) 使用以上模块:
如果您使用的是 JBoss EAP 6.1.x 及更高版本或 EAP 7,请使用以下内容:
<?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>
如果JBoss EAP 6.0.x,则使用下面
<?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>
注意:jboss-deployment-structure.xml模块上的meta-inf是在JBoss EAP 6.1.0中添加的,允许META-INF 的资源是可见的。由于这在 JBoss EAP 6 中不可用。0.x,该部分允许您访问默认情况下不可见的 META-INF 目录。
注意:Spring框架模块不应包含servlet-api.jar、xml-apis.jar、jta-api.jar等资源API秒。这些 API 由 JDK 或 JBoss 实现,尝试使用不同版本的 API 将导致类加载问题和其他问题。
注意:Spring 模块应包含其所有非 Java / JavaEE 依赖项。 Spring 模块可以依赖于 JBoss 提供的 javax.api / javaee.api 和任何 public JBoss 模块,但对于其他依赖项 Spring 有诸如 aopalliance,它们需要作为资源包含在模块或另一个自定义模块中。