我想从tomcat迁移到Wildfly 10.1,所以我创建了一个Web应用程序,用于在Wildfly上测试Jersey rest Web服务。
当我运行项目时,它会根据MultiPartFeature.class
这是我的ApplicationConfigure.java
@ApplicationPath("api")
public class ApplicationConfigure extends ResourceConfig {
public ApplicationConfigure() {
register(JacksonJaxbJsonProvider.class);
register(JacksonFeature.class);
register(MultiPartFeature.class);
packages(true, "com.example.controllers");
}
}
这是错误(WildFly日志):
11:18:13,855 ERROR [org.jboss.msc.service.fail] (ServerService Thread Pool -- 69) MSC000001: Failed to start service jboss.undertow.deployment.default-server.default-host./wildfly-webapplcation: org.jboss.msc.service.StartException in service jboss.undertow.deployment.default-server.default-host./wildfly-webapplcation: java.lang.RuntimeException: RESTEASY003940: Unable to instantiate MessageBodyReader
at org.wildfly.extension.undertow.deployment.UndertowDeploymentService$1.run(UndertowDeploymentService.java:85)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
at org.jboss.threads.JBossThread.run(JBossThread.java:320)
Caused by: java.lang.RuntimeException: RESTEASY003940: Unable to instantiate MessageBodyReader
at org.jboss.resteasy.spi.ResteasyProviderFactory.registerProvider(ResteasyProviderFactory.java:1437)
at org.jboss.resteasy.spi.ResteasyProviderFactory.registerProvider(ResteasyProviderFactory.java:1368)
at org.jboss.resteasy.spi.ResteasyProviderFactory.registerProvider(ResteasyProviderFactory.java:1290)
at org.jboss.resteasy.spi.ResteasyProviderFactory.register(ResteasyProviderFactory.java:2438)
at org.jboss.resteasy.spi.ResteasyProviderFactory.register(ResteasyProviderFactory.java:99)
at org.jboss.resteasy.util.FeatureContextDelegate.register(FeatureContextDelegate.java:37)
at org.jboss.resteasy.util.FeatureContextDelegate.register(FeatureContextDelegate.java:12)
at org.glassfish.jersey.media.multipart.MultiPartFeature.configure(MultiPartFeature.java:65)
at org.jboss.resteasy.spi.ResteasyProviderFactory.registerProvider(ResteasyProviderFactory.java:1739)
at org.jboss.resteasy.spi.ResteasyProviderFactory.registerProvider(ResteasyProviderFactory.java:1368)
at org.jboss.resteasy.spi.ResteasyProviderFactory.registerProvider(ResteasyProviderFactory.java:1290)
at org.jboss.resteasy.spi.ResteasyDeployment.registration(ResteasyDeployment.java:368)
at org.jboss.resteasy.spi.ResteasyDeployment.start(ResteasyDeployment.java:250)
at org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.init(ServletContainerDispatcher.java:113)
at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.init(HttpServletDispatcher.java:36)
at io.undertow.servlet.core.LifecyleInterceptorInvocation.proceed(LifecyleInterceptorInvocation.java:117)
at org.wildfly.extension.undertow.security.RunAsLifecycleInterceptor.init(RunAsLifecycleInterceptor.java:78)
at io.undertow.servlet.core.LifecyleInterceptorInvocation.proceed(LifecyleInterceptorInvocation.java:103)
at io.undertow.servlet.core.ManagedServlet$DefaultInstanceStrategy.start(ManagedServlet.java:250)
at io.undertow.servlet.core.ManagedServlet.createServlet(ManagedServlet.java:133)
at io.undertow.servlet.core.DeploymentManagerImpl$2.call(DeploymentManagerImpl.java:546)
at io.undertow.servlet.core.DeploymentManagerImpl$2.call(DeploymentManagerImpl.java:517)
at io.undertow.servlet.core.ServletRequestContextThreadSetupAction$1.call(ServletRequestContextThreadSetupAction.java:42)
at io.undertow.servlet.core.ContextClassLoaderSetupAction$1.call(ContextClassLoaderSetupAction.java:43)
at io.undertow.servlet.api.LegacyThreadSetupActionWrapper$1.call(LegacyThreadSetupActionWrapper.java:44)
at io.undertow.servlet.api.LegacyThreadSetupActionWrapper$1.call(LegacyThreadSetupActionWrapper.java:44)
at io.undertow.servlet.api.LegacyThreadSetupActionWrapper$1.call(LegacyThreadSetupActionWrapper.java:44)
at io.undertow.servlet.api.LegacyThreadSetupActionWrapper$1.call(LegacyThreadSetupActionWrapper.java:44)
at io.undertow.servlet.api.LegacyThreadSetupActionWrapper$1.call(LegacyThreadSetupActionWrapper.java:44)
at io.undertow.servlet.core.DeploymentManagerImpl.start(DeploymentManagerImpl.java:559)
at org.wildfly.extension.undertow.deployment.UndertowDeploymentService.startContext(UndertowDeploymentService.java:101)
at org.wildfly.extension.undertow.deployment.UndertowDeploymentService$1.run(UndertowDeploymentService.java:82)
... 6 more
Caused by: java.lang.IllegalArgumentException: RESTEASY003900: Unable to find a public constructor for provider class org.glassfish.jersey.media.multipart.internal.MultiPartReaderServerSide
at org.jboss.resteasy.spi.ResteasyProviderFactory.createConstructorInjector(ResteasyProviderFactory.java:2255)
at org.jboss.resteasy.spi.ResteasyProviderFactory.createProviderInstance(ResteasyProviderFactory.java:2244)
at org.jboss.resteasy.spi.ResteasyProviderFactory.addMessageBodyReader(ResteasyProviderFactory.java:806)
at org.jboss.resteasy.spi.ResteasyProviderFactory.registerProvider(ResteasyProviderFactory.java:1432)
... 37 more
netbeans日志:
Deploying /usr/local/wildfly-10.1.0.Final/standalone/deployments/wildfly-webapplcation-1.0.war
"{
\"WFLYCTL0080: Failed services\" => {\"jboss.undertow.deployment.default-server.default-host./wildfly-webapplcation\" => \"org.jboss.msc.service.StartException in service jboss.undertow.deployment.default-server.default-host./wildfly-webapplcation: java.lang.RuntimeException: RESTEASY003940: Unable to instantiate MessageBodyReader
Caused by: java.lang.RuntimeException: RESTEASY003940: Unable to instantiate MessageBodyReader
Caused by: java.lang.IllegalArgumentException: RESTEASY003900: Unable to find a public constructor for provider class org.glassfish.jersey.media.multipart.internal.MultiPartReaderServerSide\"},
\"WFLYCTL0412: Required services that are not installed:\" => [\"jboss.undertow.deployment.default-server.default-host./wildfly-webapplcation\"],
\"WFLYCTL0180: Services with missing/unavailable dependencies\" => undefined
}"
当我删除MultiPartFeature.class
时,它的部署非常好。
Tomee
。
我该怎么办?我需要这个功能才能上传api
答案 0 :(得分:4)
作为应用程序服务器,Wildfly提供了自己的JAX-RS规范实现。这里的框架是RESTEasy而不是Jersey。
那么从日志中可以看到它:
Caused by: java.lang.RuntimeException: RESTEASY003940: Unable to instantiate MessageBodyReader
at org.jboss.resteasy.spi.ResteasyProviderFactory.registerProvider(ResteasyProviderFactory.java:1437)
RESTEasy引擎试图启动Jersey的功能,但未能这样做。在JAX-RS实现中没有那么多的统一,所以它们经常是不兼容的。
您有两种可能的解决方案
从泽西岛切换到RESTEasy。 multipart support有点不同
关闭Wildfly的RESTEasy扫描应用程序并在内部启动Jersey服务器。互联网上有很多关于它的文章。不确定哪种方法适用于您的版本。
答案 1 :(得分:0)
我遇到了这个问题,并设法通过手动调用
JerseyClientBuilder().build()
而不是ClientBuilder().build()
。
泽西客户似乎是默认客户,因此,如果您定义了另一个客户,它将是ClientBuilder().build()
选择的客户。
答案 2 :(得分:0)
我在服务器和客户端级别将 Jersey 库版本从 1.x 升级到 2.x 时遇到了这个问题。
1.服务器级别更改:
在我的 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>
在我的 servlet 部分添加了以下提供者
<servlet>
....
....
<init-param>
<param-name>jersey.config.server.provider.classnames</param-name>
<param-value>
com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider,
org.glassfish.jersey.media.multipart.MultiPartFeature
</param-value>
</init-param>
....
....
</servlet>
2.客户端级别更改:
在升级过程中,我只是将客户端相关的类包从 com.sun.jersey.api.client
更改为 org.glassfish.jersey.client
并假设所有 glassfish jersey 的默认提供程序都将在客户端实例化期间注册,而不是 {{1 }} 被初始化,主要原因是,我使用 org.jboss.resteasy.spi.ResteasyProviderFactory
来创建客户端。此外,在问题发生后,将上述客户端创建更改为以下代码段,这导致我遇到了问题
找不到非具体 Map 类型的反序列化器 [map type; class javax.ws.rs.core.MultivaluedMap, [简单类型, class java.lang.String] -> [集合类型;类 java.util.List,包含 [简单类型,类 java.lang.Object]]] .
Client client = Client.create();
Json 解析问题是由于 org.glassfish.jersey.client.JerseyInvocation#translate
方法,其中实体读取发生在消息实体输入流中,作为指定 Java 类型的实例,使用 Client client = ClientBuilder.newClient();
WebTarget webResource = client.target(url);
ClientResponse response = webResource.path(path).request("application/json")
.header("Content-Type", "application/json;charset=UTF-8")
.put(Entity.json(json), ClientResponse.class);
if (response.getStatus() < 200 || response.getStatus() > 299) {
throw new CustomException("HTTP Status: " + response.getStatus());
}
String responseInString = response.readEntity(String.class);
用于 javax.ws 以外的类型.rs.core.Response`。
最后,通过完全采用 Jersey 家族的客户端类解决了上述问题。
工作客户:
javax.ws.rs.ext.MessageBodyReader