如何配置 Glassfish 5 以使用 Moxy 作为默认提供程序?
How do I configure Glassfish 5 to use Moxy as the default Provider?
我正在将我们的 Web 应用程序从 Glassfish 3 迁移到 Glassfish 5,并且在迁移过程中我 运行 遇到了这个请求错误。
[2019-09-17T15:57:30.732-0600] [glassfish 5.0] [WARNING] [] [javax.enterprise.web] [tid: _ThreadID=241 _ThreadName=http-listener-2(27)] [timeMillis: 1568757450732] [levelValue: 900] [[
StandardWrapperValve[ClientControllers]: Servlet.service() for servlet ClientControllers threw exception
java.lang.ClassCastException: [Z cannot be cast to [Ljava.lang.Object;
at org.eclipse.yasson.internal.serializer.ObjectArraySerializer.serializeInternal(ObjectArraySerializer.java:27)
at org.eclipse.yasson.internal.serializer.AbstractContainerSerializer.serialize(AbstractContainerSerializer.java:60)
at org.eclipse.yasson.internal.serializer.AbstractContainerSerializer.serializerCaptor(AbstractContainerSerializer.java:91)
at org.eclipse.yasson.internal.serializer.ObjectSerializer.marshallProperty(ObjectSerializer.java:92)
at org.eclipse.yasson.internal.serializer.ObjectSerializer.serializeInternal(ObjectSerializer.java:59)
at org.eclipse.yasson.internal.serializer.AbstractContainerSerializer.serialize(AbstractContainerSerializer.java:60)
at org.eclipse.yasson.internal.serializer.AbstractContainerSerializer.serializerCaptor(AbstractContainerSerializer.java:91)
at org.eclipse.yasson.internal.serializer.ObjectArraySerializer.serializeInternal(ObjectArraySerializer.java:46)
at org.eclipse.yasson.internal.serializer.ObjectArraySerializer.serializeInternal(ObjectArraySerializer.java:27)
at org.eclipse.yasson.internal.serializer.AbstractContainerSerializer.serialize(AbstractContainerSerializer.java:60)
at org.eclipse.yasson.internal.Marshaller.serializeRoot(Marshaller.java:118)
at org.eclipse.yasson.internal.Marshaller.marshall(Marshaller.java:76)
at org.eclipse.yasson.internal.JsonBinding.toJson(JsonBinding.java:98)
at org.glassfish.jersey.jsonb.internal.JsonBindingProvider.writeTo(JsonBindingProvider.java:118)
at org.glassfish.jersey.message.internal.WriterInterceptorExecutor$TerminalWriterInterceptor.invokeWriteTo(WriterInterceptorExecutor.java:266)
at org.glassfish.jersey.message.internal.WriterInterceptorExecutor$TerminalWriterInterceptor.aroundWriteTo(WriterInterceptorExecutor.java:251)
at org.glassfish.jersey.message.internal.WriterInterceptorExecutor.proceed(WriterInterceptorExecutor.java:163)
at org.glassfish.jersey.server.internal.JsonWithPaddingInterceptor.aroundWriteTo(JsonWithPaddingInterceptor.java:109)
at org.glassfish.jersey.message.internal.WriterInterceptorExecutor.proceed(WriterInterceptorExecutor.java:163)
at org.glassfish.jersey.spi.ContentEncoder.aroundWriteTo(ContentEncoder.java:137)
at org.glassfish.jersey.message.internal.WriterInterceptorExecutor.proceed(WriterInterceptorExecutor.java:163)
at org.glassfish.jersey.server.internal.MappableExceptionWrapperInterceptor.aroundWriteTo(MappableExceptionWrapperInterceptor.java:85)
at org.glassfish.jersey.message.internal.WriterInterceptorExecutor.proceed(WriterInterceptorExecutor.java:163)
at org.glassfish.jersey.message.internal.MessageBodyFactory.writeTo(MessageBodyFactory.java:1135)
at org.glassfish.jersey.server.ServerRuntime$Responder.writeResponse(ServerRuntime.java:662)
at org.glassfish.jersey.server.ServerRuntime$Responder.processResponse(ServerRuntime.java:395)
at org.glassfish.jersey.server.ServerRuntime$Responder.process(ServerRuntime.java:385)
at org.glassfish.jersey.server.ServerRuntime.run(ServerRuntime.java:280)
at org.glassfish.jersey.internal.Errors.call(Errors.java:272)
at org.glassfish.jersey.internal.Errors.call(Errors.java:268)
at org.glassfish.jersey.internal.Errors.process(Errors.java:316)
at org.glassfish.jersey.internal.Errors.process(Errors.java:298)
at org.glassfish.jersey.internal.Errors.process(Errors.java:268)
at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:289)
at org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:256)
at org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:703)
at org.glassfish.jersey.servlet.WebComponent.serviceImpl(WebComponent.java:416)
at org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:370)
at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:389)
at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:342)
at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:229)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1580)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:258)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:652)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:591)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:652)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:591)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:368)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:238)
at com.sun.enterprise.v3.services.impl.ContainerMapper$HttpHandlerCallable.call(ContainerMapper.java:463)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:168)
at org.glassfish.grizzly.http.server.HttpHandler.run(HttpHandler.java:224)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:593)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:573)
at java.lang.Thread.run(Thread.java:745)
]]
Glassfish 5 似乎正在使用 JSON-B 序列化。
Glassfish 5 ignores JAXB @XmlJavaTypeAdapter annotation?
过去我们使用 moxy 和 jaxb 进行 json 绑定,因此我一直在尝试将 Moxy 注册为 Glassfish 5 中的默认提供程序。我已经按照此处的说明进行操作,没有运气.
https://howtodoinjava.com/jersey/jax-rs-jersey-moxy-json-example/
我还阅读了 Glassfish 5 文档,但没有找到任何类似的注册默认提供程序的示例。如果有人可以阐明我在配置中做错了什么,将不胜感激。我在下面提供了我的配置示例。
如何配置 Glassfish 5 以使用 Moxy 作为默认提供程序?
备注:
- 当我启动 glassfish 时,我调试了 JsonServicesContextResolver.java class 并验证了在初始化期间调用了构造函数和 getContext 方法。
- 我已经尝试删除 GridApplication.java class 并删除其在 web.xml 中的引用,认为 jersey.config.server.provider.packages 可能已经在这些包中注册了任何提供程序。我仍然有同样的错误。
JsonServicesContextResolver.java
package com.lnka.eng.grid.jersey;
import org.eclipse.persistence.jaxb.JAXBContextProperties;
import org.glassfish.jersey.moxy.json.MoxyJsonConfig;
import javax.ws.rs.ext.ContextResolver;
import javax.ws.rs.ext.Provider;
@Provider
public class JsonServicesContextResolver
implements ContextResolver<MoxyJsonConfig>
{
private MoxyJsonConfig config;
public JsonServicesContextResolver()
{
config = new MoxyJsonConfig()
.setNamespaceSeparator(':')
.setAttributePrefix("")
.setValueWrapper("value")
.property(JAXBContextProperties.JSON_WRAPPER_AS_ARRAY_NAME, true)
.setFormattedOutput(true)
.setIncludeRoot(true)
.setMarshalEmptyCollections(true);
}
@Override
public MoxyJsonConfig getContext(Class<?> objectType)
{
return config;
}
}
ProgramsController.java
package com.lnka.eng.view.controller;
@Path("/mgmt/programs/")
@Stateless
@Transactional(Transactional.TxType.NOT_SUPPORTED)
public class ProgramsController extends Controller
{
@GET
@Path("/list/")
@Produces(MediaType.APPLICATION_JSON)
public Response getProgramsList()
{
List<Program> programs = getPrograms();
return Response.ok(programs).build();
}
}
GridApplication.java
package com.lnka.eng.grid.jersey;
import com.lnka.eng.view.controller.ProgramsController;
import javax.ws.rs.core.Application;
import java.util.HashSet;
import java.util.Set;
public class GridApplication extends Application
{
//Add Service APIs
@Override
public Set<Class<?>> getClasses()
{
Set<Class<?>> resources = new HashSet<Class<?>>();
//register REST modules
resources.add(ProgramsController.class);
//Manually adding MOXyJSONFeature
resources.add(org.glassfish.jersey.moxy.json.MoxyJsonFeature.class);
//Configure Moxy behavior
resources.add(JsonServicesContextResolver.class);
return resources;
}
}
web.xml
我已经删除了这个文件中一些我认为不相关的配置(安全、ejb 配置等)
<web-app version="2.5"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<display-name>Grid</display-name>
<servlet>
<servlet-name>JerseyServiceApplications</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>javax.ws.rs.core.Application</param-name>
<param-value>com.lnka.eng.grid.jersey.GridApplication</param-value>
</init-param>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>com.lnka.eng.grid.service;com.lnka.eng.grid.jersey</param-value>
</init-param>
<init-param>
<param-name>jersey.config.server.provider.classnames</param-name>
<param-value>org.glassfish.jersey.message.GZipEncoder</param-value>
</init-param>
<init-param>
<param-name>debug</param-name>
<param-value>false</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet>
<servlet-name>ClientControllers</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>javax.ws.rs.core.Application</param-name>
<param-value>com.lnka.eng.grid.jersey.GridApplication</param-value>
</init-param>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>
com.lnka.eng.view.controller,
com.lnka.eng.grid.jersey
</param-value>
</init-param>
<init-param>
<param-name>jersey.config.server.provider.classnames</param-name>
<param-value>
org.glassfish.jersey.message.GZipEncoder
</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>ClientControllers</servlet-name>
<url-pattern>/client/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>JerseyServiceApplications</servlet-name>
<url-pattern>/resources/*</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>480</session-timeout>
</session-config>
</web-app>
问题是我们需要更新 web.xml 以将 MoxyConfig 包含在会话配置范围内。我还遗漏了我们的一位听众的一些配置,但相关代码在下面。
以下内容被放置在每个 <servlet>...</servlet>
标签中。
<init-param>
<param-name>jersey.config.server.jsonFeature</param-name>
<param-value>MoxyJsonFeature</param-value>
</init-param>
我正在将我们的 Web 应用程序从 Glassfish 3 迁移到 Glassfish 5,并且在迁移过程中我 运行 遇到了这个请求错误。
[2019-09-17T15:57:30.732-0600] [glassfish 5.0] [WARNING] [] [javax.enterprise.web] [tid: _ThreadID=241 _ThreadName=http-listener-2(27)] [timeMillis: 1568757450732] [levelValue: 900] [[
StandardWrapperValve[ClientControllers]: Servlet.service() for servlet ClientControllers threw exception
java.lang.ClassCastException: [Z cannot be cast to [Ljava.lang.Object;
at org.eclipse.yasson.internal.serializer.ObjectArraySerializer.serializeInternal(ObjectArraySerializer.java:27)
at org.eclipse.yasson.internal.serializer.AbstractContainerSerializer.serialize(AbstractContainerSerializer.java:60)
at org.eclipse.yasson.internal.serializer.AbstractContainerSerializer.serializerCaptor(AbstractContainerSerializer.java:91)
at org.eclipse.yasson.internal.serializer.ObjectSerializer.marshallProperty(ObjectSerializer.java:92)
at org.eclipse.yasson.internal.serializer.ObjectSerializer.serializeInternal(ObjectSerializer.java:59)
at org.eclipse.yasson.internal.serializer.AbstractContainerSerializer.serialize(AbstractContainerSerializer.java:60)
at org.eclipse.yasson.internal.serializer.AbstractContainerSerializer.serializerCaptor(AbstractContainerSerializer.java:91)
at org.eclipse.yasson.internal.serializer.ObjectArraySerializer.serializeInternal(ObjectArraySerializer.java:46)
at org.eclipse.yasson.internal.serializer.ObjectArraySerializer.serializeInternal(ObjectArraySerializer.java:27)
at org.eclipse.yasson.internal.serializer.AbstractContainerSerializer.serialize(AbstractContainerSerializer.java:60)
at org.eclipse.yasson.internal.Marshaller.serializeRoot(Marshaller.java:118)
at org.eclipse.yasson.internal.Marshaller.marshall(Marshaller.java:76)
at org.eclipse.yasson.internal.JsonBinding.toJson(JsonBinding.java:98)
at org.glassfish.jersey.jsonb.internal.JsonBindingProvider.writeTo(JsonBindingProvider.java:118)
at org.glassfish.jersey.message.internal.WriterInterceptorExecutor$TerminalWriterInterceptor.invokeWriteTo(WriterInterceptorExecutor.java:266)
at org.glassfish.jersey.message.internal.WriterInterceptorExecutor$TerminalWriterInterceptor.aroundWriteTo(WriterInterceptorExecutor.java:251)
at org.glassfish.jersey.message.internal.WriterInterceptorExecutor.proceed(WriterInterceptorExecutor.java:163)
at org.glassfish.jersey.server.internal.JsonWithPaddingInterceptor.aroundWriteTo(JsonWithPaddingInterceptor.java:109)
at org.glassfish.jersey.message.internal.WriterInterceptorExecutor.proceed(WriterInterceptorExecutor.java:163)
at org.glassfish.jersey.spi.ContentEncoder.aroundWriteTo(ContentEncoder.java:137)
at org.glassfish.jersey.message.internal.WriterInterceptorExecutor.proceed(WriterInterceptorExecutor.java:163)
at org.glassfish.jersey.server.internal.MappableExceptionWrapperInterceptor.aroundWriteTo(MappableExceptionWrapperInterceptor.java:85)
at org.glassfish.jersey.message.internal.WriterInterceptorExecutor.proceed(WriterInterceptorExecutor.java:163)
at org.glassfish.jersey.message.internal.MessageBodyFactory.writeTo(MessageBodyFactory.java:1135)
at org.glassfish.jersey.server.ServerRuntime$Responder.writeResponse(ServerRuntime.java:662)
at org.glassfish.jersey.server.ServerRuntime$Responder.processResponse(ServerRuntime.java:395)
at org.glassfish.jersey.server.ServerRuntime$Responder.process(ServerRuntime.java:385)
at org.glassfish.jersey.server.ServerRuntime.run(ServerRuntime.java:280)
at org.glassfish.jersey.internal.Errors.call(Errors.java:272)
at org.glassfish.jersey.internal.Errors.call(Errors.java:268)
at org.glassfish.jersey.internal.Errors.process(Errors.java:316)
at org.glassfish.jersey.internal.Errors.process(Errors.java:298)
at org.glassfish.jersey.internal.Errors.process(Errors.java:268)
at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:289)
at org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:256)
at org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:703)
at org.glassfish.jersey.servlet.WebComponent.serviceImpl(WebComponent.java:416)
at org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:370)
at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:389)
at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:342)
at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:229)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1580)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:258)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:652)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:591)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:652)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:591)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:368)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:238)
at com.sun.enterprise.v3.services.impl.ContainerMapper$HttpHandlerCallable.call(ContainerMapper.java:463)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:168)
at org.glassfish.grizzly.http.server.HttpHandler.run(HttpHandler.java:224)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:593)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:573)
at java.lang.Thread.run(Thread.java:745)
]]
Glassfish 5 似乎正在使用 JSON-B 序列化。 Glassfish 5 ignores JAXB @XmlJavaTypeAdapter annotation?
过去我们使用 moxy 和 jaxb 进行 json 绑定,因此我一直在尝试将 Moxy 注册为 Glassfish 5 中的默认提供程序。我已经按照此处的说明进行操作,没有运气.
https://howtodoinjava.com/jersey/jax-rs-jersey-moxy-json-example/
我还阅读了 Glassfish 5 文档,但没有找到任何类似的注册默认提供程序的示例。如果有人可以阐明我在配置中做错了什么,将不胜感激。我在下面提供了我的配置示例。
如何配置 Glassfish 5 以使用 Moxy 作为默认提供程序?
备注:
- 当我启动 glassfish 时,我调试了 JsonServicesContextResolver.java class 并验证了在初始化期间调用了构造函数和 getContext 方法。
- 我已经尝试删除 GridApplication.java class 并删除其在 web.xml 中的引用,认为 jersey.config.server.provider.packages 可能已经在这些包中注册了任何提供程序。我仍然有同样的错误。
JsonServicesContextResolver.java
package com.lnka.eng.grid.jersey;
import org.eclipse.persistence.jaxb.JAXBContextProperties;
import org.glassfish.jersey.moxy.json.MoxyJsonConfig;
import javax.ws.rs.ext.ContextResolver;
import javax.ws.rs.ext.Provider;
@Provider
public class JsonServicesContextResolver
implements ContextResolver<MoxyJsonConfig>
{
private MoxyJsonConfig config;
public JsonServicesContextResolver()
{
config = new MoxyJsonConfig()
.setNamespaceSeparator(':')
.setAttributePrefix("")
.setValueWrapper("value")
.property(JAXBContextProperties.JSON_WRAPPER_AS_ARRAY_NAME, true)
.setFormattedOutput(true)
.setIncludeRoot(true)
.setMarshalEmptyCollections(true);
}
@Override
public MoxyJsonConfig getContext(Class<?> objectType)
{
return config;
}
}
ProgramsController.java
package com.lnka.eng.view.controller;
@Path("/mgmt/programs/")
@Stateless
@Transactional(Transactional.TxType.NOT_SUPPORTED)
public class ProgramsController extends Controller
{
@GET
@Path("/list/")
@Produces(MediaType.APPLICATION_JSON)
public Response getProgramsList()
{
List<Program> programs = getPrograms();
return Response.ok(programs).build();
}
}
GridApplication.java
package com.lnka.eng.grid.jersey;
import com.lnka.eng.view.controller.ProgramsController;
import javax.ws.rs.core.Application;
import java.util.HashSet;
import java.util.Set;
public class GridApplication extends Application
{
//Add Service APIs
@Override
public Set<Class<?>> getClasses()
{
Set<Class<?>> resources = new HashSet<Class<?>>();
//register REST modules
resources.add(ProgramsController.class);
//Manually adding MOXyJSONFeature
resources.add(org.glassfish.jersey.moxy.json.MoxyJsonFeature.class);
//Configure Moxy behavior
resources.add(JsonServicesContextResolver.class);
return resources;
}
}
web.xml
我已经删除了这个文件中一些我认为不相关的配置(安全、ejb 配置等)
<web-app version="2.5"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<display-name>Grid</display-name>
<servlet>
<servlet-name>JerseyServiceApplications</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>javax.ws.rs.core.Application</param-name>
<param-value>com.lnka.eng.grid.jersey.GridApplication</param-value>
</init-param>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>com.lnka.eng.grid.service;com.lnka.eng.grid.jersey</param-value>
</init-param>
<init-param>
<param-name>jersey.config.server.provider.classnames</param-name>
<param-value>org.glassfish.jersey.message.GZipEncoder</param-value>
</init-param>
<init-param>
<param-name>debug</param-name>
<param-value>false</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet>
<servlet-name>ClientControllers</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>javax.ws.rs.core.Application</param-name>
<param-value>com.lnka.eng.grid.jersey.GridApplication</param-value>
</init-param>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>
com.lnka.eng.view.controller,
com.lnka.eng.grid.jersey
</param-value>
</init-param>
<init-param>
<param-name>jersey.config.server.provider.classnames</param-name>
<param-value>
org.glassfish.jersey.message.GZipEncoder
</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>ClientControllers</servlet-name>
<url-pattern>/client/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>JerseyServiceApplications</servlet-name>
<url-pattern>/resources/*</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>480</session-timeout>
</session-config>
</web-app>
问题是我们需要更新 web.xml 以将 MoxyConfig 包含在会话配置范围内。我还遗漏了我们的一位听众的一些配置,但相关代码在下面。
以下内容被放置在每个 <servlet>...</servlet>
标签中。
<init-param>
<param-name>jersey.config.server.jsonFeature</param-name>
<param-value>MoxyJsonFeature</param-value>
</init-param>