[英]Jersey 2 on Jboss 7
Has anyone had success deploying Jersey 2.x with JBoss 7.x? 有没有人成功使用JBoss 7.x部署Jersey 2.x? I've tried deploying Jersey 2.5 with JBoss 7.1.1 but encountered errors like:
我尝试使用JBoss 7.1.1部署Jersey 2.5,但遇到了如下错误:
"java.lang.NoSuchMethodError: javax.ws.rs.core.Application.getProperties()Ljava/util/Map;"
I believe this issue is because JBoss comes bundled with RestEasy which is a JAX-RS 1.0 implementation while Jersey is a JAX-RS 2.0 implementation. 我相信这个问题是因为JBoss捆绑了RestEasy,这是一个JAX-RS 1.0实现,而Jersey是一个JAX-RS 2.0实现。 So I took the following steps to disable RestEasy:
所以我采取了以下步骤来禁用RestEasy:
1) Added the following to my web.xml: 1)在我的web.xml中添加了以下内容:
<context-param>
<param-name>resteasy.scan</param-name>
<param-value>false</param-value>
</context-param>
<context-param>
<param-name>resteasy.scan.providers</param-name>
<param-value>false</param-value>
</context-param>
<context-param>
<param-name>resteasy.scan.resources</param-name>
<param-value>false</param-value>
</context-param>
2) Followed the discussion here , I modified my JBoss' standalone.xml, module.xml, and domain.xml to remove all references to JAXRS1.1 / RestEasy. 2)在这里讨论之后,我修改了JBoss的standalone.xml,module.xml和domain.xml以删除对JAXRS1.1 / RestEasy的所有引用。
3) This led to another error: "java.lang.NoClassDefFoundError: org/objectweb/asm/ClassVisitor" which I resolved by adding the following to my pom.xml: 3)这导致了另一个错误:“java.lang.NoClassDefFoundError:org / objectweb / asm / ClassVisitor”,我通过将以下内容添加到我的pom.xml来解决:
<dependency>
<groupId>asm</groupId>
<artifactId>asm</artifactId>
<version>3.3.1</version>
</dependency>
So finally my app deploys without errors but now I cannot seem to access any of my Jersey resources. 所以最后我的应用程序部署没有错误,但现在我似乎无法访问我的任何泽西资源。 Jetty 8 works fine, however.
但Jetty 8工作正常。 I also was able to run Jersey 1.x without having to take steps #2 and #3 but I would prefer to use Jersey 2.x if possible.
我也能够运行Jersey 1.x,而不必采取步骤#2和#3,但如果可能的话,我更愿意使用Jersey 2.x.
Additionally I've also tried creating a jboss-deployment-structure.xml file, but then I still encounter the previous errors like "java.lang.NoSuchMethodError: javax.ws.rs.core.Application.getProperties()Ljava/util/Map;" 另外我还尝试创建一个jboss-deployment-structure.xml文件,但后来我仍然遇到之前的错误,如“java.lang.NoSuchMethodError:javax.ws.rs.core.Application.getProperties()Ljava / util /地图;”
<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure>
<deployment>
<exclusions>
<module name="org.jboss.resteasy.resteasy-atom-provider"/>
<module name="org.jboss.resteasy.resteasy-cdi"/>
<module name="org.jboss.resteasy.resteasy-jackson-provider"/>
<module name="org.jboss.resteasy.resteasy-jaxb-provider"/>
<module name="org.jboss.resteasy.resteasy-jaxrs"/>
<module name="org.jboss.resteasy.resteasy-jettison-provider"/>
<module name="org.jboss.resteasy.resteasy-jsapi"/>
<module name="org.jboss.resteasy.resteasy-multipart-provider"/>
<module name="org.jboss.resteasy.resteasy-yaml-provider"/>
<module name="org.apache.log4j"/>
<module name="org.apache.commons.pool"/>
<module name="javax.ws.rs.api"/>
</exclusions>
</deployment>
</jboss-deployment-structure>
Has anyone had any luck with Jboss and Jersey 2.x? Jboss和Jersey 2.x有没有运气好吗? Any help would be appreciated.
任何帮助,将不胜感激。
You can use Jersey 2 on JBoss 7 if you configure your jboss-deployment-structure.xml similar to this: 如果配置与此类似的jboss-deployment-structure.xml,则可以在JBoss 7上使用Jersey 2:
<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure>
<deployment>
<exclude-subsystems>
<subsystem name="resteasy" />
</exclude-subsystems>
<exclusions>
<module name="javaee.api" />
<module name="javax.ws.rs.api"/>
<module name="org.jboss.resteasy.resteasy-jaxrs" />
</exclusions>
<local-last value="true" />
</deployment>
</jboss-deployment-structure>
Because JBoss 7 includes dependencies of modules, it is not sufficient to exclude the resteasy module itself but you need to exclude the whole javaee.api module. 因为JBoss 7包含模块的依赖项,所以仅排除resteasy模块本身是不够的,但是您需要排除整个javaee.api模块。 Also make sure to not exclude too many modules.
另外,请确保不要排除太多模块。 This may also break your application - the example above is sufficient to disable resteasy.
这也可能会破坏您的应用程序 - 上面的示例足以禁用resteasy。
As you already discovered, you still need to include the following lines in your web.xml 如您所知,您仍需要在web.xml中包含以下行
<context-param>
<param-name>resteasy.scan</param-name>
<param-value>false</param-value>
</context-param>
<context-param>
<param-name>resteasy.scan.providers</param-name>
<param-value>false</param-value>
</context-param>
<context-param>
<param-name>resteasy.scan.resources</param-name>
<param-value>false</param-value>
</context-param>
This is similar to this question 这与此问题类似
So bit of copy/paste with just different subsystem at play. 所以只需要不同的子系统即可复制/粘贴。
You should exclude jaxrs subsystem from being activated for your deployment add this into META-INF/jboss-deployment-structure.xml 您应该排除为部署激活jaxrs子系统,将其添加到META-INF / jboss-deployment-structure.xml中
<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.2">
<deployment>
<!-- exclude-subsystem prevents a subsystems deployment unit processors running on a deployment -->
<!-- which gives basically the same effect as removing the subsystem, but it only affects single deployment -->
<exclude-subsystems>
<subsystem name="jaxrs" />
</exclude-subsystems>
<!-- This is needed in any case even if you don't use exclude-subsystem above-->
<exclusions>
<module name="javax.ws.rs.api" />
</exclusions>
<deployment>
</jboss-deployment-structure>
or you can go to standalone.xml and remove subsystem there. 或者您可以转到standalone.xml并删除子系统。 To do so, you need to remove
为此,您需要删除
<subsystem xmlns="urn:jboss:domain:jaxrs:1.x">
...
...
<subsystem>
part of configuration, extension part of on top can stay it wont hurt either way. 配置的一部分,顶部的扩展部分可以保持它不会伤害任何方式。 or you can connect to server with CLI and run
或者您可以使用CLI连接到服务器并运行
/subsystem=jaxrs:remove()
In any case I would recommend to read bit about class loading in AS7 https://docs.jboss.org/author/display/AS72/Class+Loading+in+AS7 无论如何,我建议在AS7中阅读有关类加载的内容https://docs.jboss.org/author/display/AS72/Class+Loading+in+AS7
Just a note, exclude-subsystems functionality and deployment-strucure:1.2 was added in 7.1.2 and as such will not work on on 7.1.1. 只是注意,排除子系统功能和部署结构: 在7.1.2中添加了 1.2, 因此在7.1.1上不起作用。
You can still remove jaxrs subsystem but that affects whole server. 您仍然可以删除jaxrs子系统,但这会影响整个服务器。
I had almost the very same issue ( https://stackoverflow.com/a/38273524/4534078 ): 我几乎有同样的问题( https://stackoverflow.com/a/38273524/4534078 ):
"Need to run Jersey 2.23.1 web app, already running on Tomcat7 in JBoss 7.1.1. " “需要运行Jersey 2.23.1网络应用程序,已经在JBoss 7.1.1中的 Tomcat7上运行。 ”
Unfortunately, nothing here worked for me, but some pieces were handy taking me towards a final solution: 不幸的是,这里没有任何东西对我有用,但是有些东西很方便带我走向最终的解决方案:
Turn off Resteasy package scanning in your web.xml: 关闭web.xml中的Resteasy包扫描:
<context-param> <param-name>resteasy.scan</param-name> <param-value>false</param-value> </context-param> <context-param> <param-name>resteasy.scan.providers</param-name> <param-value>false</param-value> </context-param> <context-param> <param-name>resteasy.scan.resources</param-name> <param-value>false</param-value> </context-param>
Remove all tags with "jaxrs" from standalone.xml. 从standalone.xml中删除所有带有“jaxrs”的标签。 Otherwise you will still face LinkageError because JBoss keeps 1.1 spec "on".
否则你仍将面临LinkageError,因为JBoss保持1.1规范“on”。
Create yourApp.war!WEB-INF\\jboss-deployment-structure.xml just like is pointed out here: https://docs.jboss.org/author/display/AS7/Class+Loading+in+AS7#ClassLoadinginAS7-JBossDeploymentStructureFile 创建yourApp.war!WEB-INF \\ jboss-deployment-structure.xml就像这里指出的那样: https ://docs.jboss.org/author/display/AS7/Class+Loading+in+AS7#ClassLoadinginAS7-JBossDeploymentStructureFile
This way, not only: 这样,不仅:
java.lang.NoSuchMethodError: javax.ws.rs.core.Application.getProperties()Ljava/util/Map;
Disapears, but also, JAXB works fine (No ClassNotFoundException for javax.xml.bind.JAXBException
once module javax.xml.bind.api
is also activated). 消失,但是,JAXB工作正常(一旦模块
javax.xml.bind.api
也被激活, ClassNotFoundException for javax.xml.bind.JAXBException
没有ClassNotFoundException for javax.xml.bind.JAXBException
)。
Obs1 : The original question is mixing jersey 1.x with jersey 2.x. Obs1 :最初的问题是混合球衣1.x和球衣2.x. There is no PojoMappingFeature in jersey 2.x and base package is
org.glassfish.jersey
. 在球衣2.x中没有PojoMappingFeature,而基础包是
org.glassfish.jersey
。 Take a look at https://jersey.java.net/documentation/latest/migration.html#mig-1-x-json 看看https://jersey.java.net/documentation/latest/migration.html#mig-1-x-json
Obs2 : I have also tried other approaches like extending ResourceConfig and scanning packages from there or registering classes directly. Obs2 :我还尝试过其他方法,比如扩展ResourceConfig并从那里扫描包或直接注册类。 Nothing worked like the proper documentation in item 3. So kept my servlet untouched:
没有什么比第3项中的正确文档更有效。所以保持我的servlet不受影响:
<servlet>
<servlet-name>WebNize REST Service</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>br.com.webnize.rest.service</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>WebNize REST Service</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
I hope it helps! 我希望它有所帮助!
Here's the combination that worked for me (much of it came from the other answers in this post - thanks everyone!). 这是对我有用的组合(大部分来自这篇文章中的其他答案 - 感谢大家!)。
At this point the web app deployed successfully without error, but I was getting 404 trying to access my REST service. 此时Web应用程序已成功部署且没有错误,但我正在尝试404尝试访问我的REST服务。
Following on from Clemens82's answer , After excluding the javaee.api module, I encountered this problem: 继Clemens82的回答之后,在排除了javaee.api模块之后,我遇到了这个问题:
java.lang.NoClassDefFoundError: javax/xml/ws/Endpoint
at java.lang.Class.getDeclaredMethods0(Native Method) [rt.jar:1.7.0_72]
at java.lang.Class.privateGetDeclaredMethods(Class.java:2615) [rt.jar:1.7.0_72]
at java.lang.Class.getDeclaredMethods(Class.java:1860) [rt.jar:1.7.0_72]
at org.springframework.core.type.StandardAnnotationMetadata.getAnnotatedMethods(StandardAnnotationMetadata.java:152) [spring-core-4.2.5.RELEASE.jar:4.2.5.RELEASE]
To fix it, I had to add the javax.xml.ws.api dependency into jboss-deployment-structure.xml. 要修复它,我必须将javax.xml.ws.api依赖项添加到jboss-deployment-structure.xml中。 Additionally, I added the javax.servlet.api as this should be provided by container if using servlets.
另外,我添加了javax.servlet.api,因为如果使用servlet,它应该由容器提供。
<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure>
<deployment>
<dependencies>
<module name="javax.xml.ws.api" /> <!-- Required due to exclusion of javaee.api below -->
<module name="javax.servlet.api" /> <!-- Required due to exclusion of javaee.api below -->
</dependencies>
<exclude-subsystems>
<subsystem name="resteasy" />
</exclude-subsystems>
<exclusions>
<module name="javaee.api" />
<module name="javax.ws.rs.api"/>
<module name="org.jboss.resteasy.resteasy-jaxrs" />
</exclusions>
<local-last value="true" />
</deployment>
</jboss-deployment-structure>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.