简体   繁体   English

将resteasy-spring模块加载到WildFly ClassNotFoundException中

[英]Loading resteasy-spring module into WildFly ClassNotFoundException

After setting up a small JAX-RS application which I deployed on WildFly I am trying to add Spring support to RestEasy. 设置了我在WildFly上部署的小型JAX-RS应用程序之后,我试图为RestEasy添加Spring支持。 I want to use the resteasy-spring module which is included in WildFly. 我想使用WildFly中包含的resteasy-spring模块。 When deploying the WAR I get a ClassNotFoundException: 部署WAR时,出现ClassNotFoundException:

 Caused by: java.lang.ClassNotFoundException: org.jboss.resteasy.plugins.spring.SpringContextLoaderListener from [Module "deployment.mk-backend-8.0.0-SNAPSHOT.war:main" from Service Module Loader]
at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:197) [jboss-modules.jar:1.3.0.Final]
at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:443) [jboss-modules.jar:1.3.0.Final]
at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:431) [jboss-modules.jar:1.3.0.Final]
at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:373) [jboss-modules.jar:1.3.0.Final]
at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:118) [jboss-modules.jar:1.3.0.Final]
at org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService.addListener(UndertowDeploymentInfoService.java:1145)
at org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService.createServletConfig(UndertowDeploymentInfoService.java:734)
... 6 more

I included the module in my Manifest file which looks like this: 我将模块包含在清单文件中,该文件如下所示:

Manifest-Version: 1.0
Dependencies: org.jboss.resteasy.resteasy-spring export

In my web.xml I included the SpringContextLoaderListener 在我的web.xml中,我包含了SpringContextLoaderListener

<listener>
    <listener-class>
        org.jboss.resteasy.plugins.spring.SpringContextLoaderListener
    </listener-class>
</listener>

I am completely new to WildFly. 我是WildFly的新手。 I went through a lot of documentation but I can't find anything that helps me.. What am I doing wrong? 我浏览了很多文档,但找不到任何可以帮助我的东西。我在做什么错?

I was dealing with a very similar issue... If you don't include a dependency in WEB-INF/lib you can force Wildfly to load this dependency from server classpath, or even exclude it if it's conflicting with specific lib versions that you used in your project. 我正在处理一个非常类似的问题...如果您未在WEB-INF / lib中包含依赖项,则可以强制Wildfly从服务器类路径中加载此依赖项,如果与特定的lib版本冲突,甚至可以将其排除在您的项目中使用。 All you have to do is create the following XML file and save it in WEB-INF/jboss-deployment-structure.xml 您要做的就是创建以下XML文件并将其保存在WEB-INF/jboss-deployment-structure.xml

<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure>
    <deployment>
    <exclusions>
        <module name="org.jboss.resteasy.resteasy-jackson2-provider" />
    </exclusions>
    <dependencies>
        <module name="org.jboss.resteasy.resteasy-jackson-provider" services="import" />
        <module name="org.apache.httpcomponents" services="import"/>
        <module name="org.apache.commons.io" services="import"/>
    </dependencies>
</deployment>
</jboss-deployment-structure>

**You should notice that the markup inside the nodes <exclusion> and <dependencies> are just sample code, you should replace it with your own needed configuration. **您应注意,节点<exclusion><dependencies>中的标记只是示例代码,应将其替换为自己所需的配置。

Maybe the missing dependency on your project is marked as private on WildFly lib. 也许对项目缺少的依赖项在WildFly lib上被标记为私有。 Open the directory %JBOSS_HOME%/modules/system/layers/base/org/jboss/resteasy and check if the lib exists or if the module.xml of that lib contains the following markup 打开目录%JBOSS_HOME%/modules/system/layers/base/org/jboss/resteasy并检查该库是否存在,或者该库的module.xml是否包含以下标记

<properties>
    <property name="jboss.api" value="private"/>
</properties>

If a WildFly dependency is private, you should explicitly include it on the XML shown above (jboss-deployment-structure.xml). 如果WildFly依赖项是私有的,则应在上面显示的XML(jboss-deployment-structure.xml)中明确包含它。 Otherwise, you just have to use it, there's no need to include the lib in your WEB-INF/lib nor manifest.mf file. 否则,您只需要使用它,就无需在您的WEB-INF / lib或manifest.mf文件中包含该库。 However, if the dependency is not available on WildFly, I recommend you to include it in you WEB-INF/lib. 但是,如果WildFly上不存在依赖项,建议您将其包括在WEB-INF / lib中。

For more information, check ClassNotFoundException for ObjectMapper on WildFly 8.1 有关更多信息,请在WildFly 8.1上检查ObjectMapper的ClassNotFoundException。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM