所有maven的家属 - 提供
的JBoss部署结构 是不是?
<deployment>
<dependencies>
<module name="by.lib" meta-inf="export" export="true"/>
<module name="org.jboss.resteasy.resteasy-jackson2-provider" services="import"/>
<!--<module name="com.fasterxml.jackson.jaxrs.jackson-jaxrs-json-provider" export="true"/>-->
<!--<module name="org.jboss.resteasy.resteasy-jaxrs" export="true"/>-->
<!--<module name="com.fasterxml.jackson.core.jackson-databind" export="true"/>-->
<!--<module name="com.fasterxml.jackson.core.jackson-core" export="true"/>-->
<!--<module name="com.fasterxml.jackson.core.jackson-annotations" export="true"/>-->
<!--<module name="org.jboss.resteasy.resteasy-jackson2-provider" export="true"/>-->
</dependencies>
<exclude-subsystems>
<subsystem name="logging"/>
<subsystem name="resteasy"/>
</exclude-subsystems>
</deployment>
在模块中,我对jackson-jaxrs-base-2.8.5
有所依赖我发现了不同的错误
13:10:27,005 ERROR [org.jboss.msc.service.fail] (ServerService Thread Pool -- 59) MSC000001: Failed to start service jboss.undertow.deployment.default-server.default-host./: org.jboss.msc.service.StartException in service jboss.undertow.deployment.default-server.default-host./: com.google.common.util.concurrent.ExecutionError: java.lang.NoClassDefFoundError: Failed to link com/fasterxml/jackson/jaxrs/base/ProviderBase (Module "by.lib:main" from local module loader @1c2c22f3 (finder: local module finder @18e8568 (roots: D:\Work\Server_10.1.0\modules,D:\Work\Server_10.1.0\modules\system\layers\base))): javax/ws/rs/ext/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:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
at org.jboss.threads.JBossThread.run(JBossThread.java:320)
Caused by: com.google.common.util.concurrent.ExecutionError: java.lang.NoClassDefFoundError: Failed to link com/fasterxml/jackson/jaxrs/base/ProviderBase (Module "by.lib:main" from local module loader @1c2c22f3 (finder: local module finder @18e8568 (roots: D:\Work\Server_10.1.0\modules,D:\Work\Server_10.1.0\modules\system\layers\base))): javax/ws/rs/ext/MessageBodyReader
at com.google.common.cache.LocalCache$Segment.get(LocalCache.java:2201)
at com.google.common.cache.LocalCache.get(LocalCache.java:3937)
或
13:14:10,114 ERROR [org.jboss.msc.service.fail] (ServerService Thread Pool -- 25) MSC000001: Failed to start service jboss.undertow.deployment.default-server.default-host./: org.jboss.msc.service.StartException in service jboss.undertow.deployment.default-server.default-host./: com.google.common.util.concurrent.ExecutionError: java.lang.NoClassDefFoundError: Failed to link com/fasterxml/jackson/jaxrs/base/ProviderBase (Module "by.lib:main" from local module loader @1c2c22f3 (finder: local module finder @18e8568 (roots: D:\Work\Server_10.1.0\modules,D:\Work\Server_10.1.0\modules\system\layers\base))): javax/ws/rs/ext/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:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
at org.jboss.threads.JBossThread.run(JBossThread.java:320)
Caused by: com.google.common.util.concurrent.ExecutionError: java.lang.NoClassDefFoundError: Failed to link com/fasterxml/jackson/jaxrs/base/ProviderBase (Module "by.lib:main" from local module loader @1c2c22f3 (finder: local module finder @18e8568 (roots: D:\Work\Server_10.1.0\modules,D:\Work\Server_10.1.0\modules\system\layers\base))): javax/ws/rs/ext/MessageBodyReader
at com.google.common.cache.LocalCache$Segment.get(LocalCache.java:2201)
at com.google.common.cache.LocalCache.get(LocalCache.java:3937)
at com.google.common.cache.LocalCache.getOrLoad(LocalCache.java:3941)
at com.google.common.cache.LocalCache$LocalLoadingCache.get(LocalCache.java:4824)
当我尝试
时@Provider
@Produces(MediaType.APPLICATION_JSON)
public class ConfiguredRESTProvider implements ContextResolver<ObjectMapper> {
private static ObjectMapper mapper;
static {
mapper = new ObjectMapper();
AnnotationIntrospector primary = new JacksonAnnotationIntrospector();
AnnotationIntrospector secondary = new JaxbAnnotationIntrospector(mapper.getTypeFactory());
AnnotationIntrospector pair = AnnotationIntrospectorPair.create(primary, secondary);
mapper.setAnnotationIntrospector(pair);
mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, true);
// TODO Разбраться почему не отрабатывае? ("balanceAmount": 2.41E8)
mapper.configure(SerializationFeature.WRITE_BIGDECIMAL_AS_PLAIN, true);
mapper.configure(JsonGenerator.Feature.WRITE_BIGDECIMAL_AS_PLAIN, true);
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
// mapper.configure(JsonGenerator.Feature.WRITE_NUMBERS_AS_STRINGS,true);
mapper.setSerializationInclusion(JsonInclude.Include.NON_EMPTY);
}
// public void ConfiguredRESTProvider() {
// // ObjectMapper mapper = new ObjectMapper();
// ObjectMapper mapper = locateMapper(type, json);
// ObjectMapper mapper = super._mapperConfig.getDefaultMapper();
// // AnnotationIntrospector primary = new JacksonAnnotationIntrospector();
// // AnnotationIntrospector secondary = new JaxbAnnotationIntrospector(mapper.getTypeFactory());
// // AnnotationIntrospector pair = AnnotationIntrospectorPair.create(primary, secondary);
// // mapper.setAnnotationIntrospector(pair);
//
// mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, true);
// // TODO Разбраться почему не отрабатывае? ("balanceAmount": 2.41E8)
// mapper.configure(SerializationFeature.WRITE_BIGDECIMAL_AS_PLAIN, true);
// mapper.configure(JsonGenerator.Feature.WRITE_BIGDECIMAL_AS_PLAIN, true);
// mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
// // mapper.configure(JsonGenerator.Feature.WRITE_NUMBERS_AS_STRINGS,true);
// mapper.setSerializationInclusion(JsonInclude.Include.NON_EMPTY);
// super.setMapper(mapper);
// }
@Override
public ObjectMapper getContext(Class<?> aClass) {
return mapper;
}
}
Jboss结构
<deployment>
<dependencies>
<module name="by.lib" meta-inf="export" export="true" services="import"/>
<module name="org.jboss.resteasy.resteasy-jackson2-provider" services="import"/>
<!--<module name="org.jboss.resteasy.resteasy-jackson2-provider" export="true"/>-->
<!--<module name="com.fasterxml.jackson.jaxrs.jackson-jaxrs-json-provider" export="true"/>-->
<!--<module name="org.jboss.resteasy.resteasy-jaxrs" export="true"/>-->
<!--<module name="com.fasterxml.jackson.core.jackson-databind" export="true"/>-->
<!--<module name="com.fasterxml.jackson.core.jackson-core" export="true"/>-->
<!--<module name="com.fasterxml.jackson.core.jackson-annotations" export="true"/>-->
<!--<module name="org.jboss.resteasy.resteasy-jackson2-provider" export="true"/>-->
</dependencies>
<exclusions>
<module name="org.jboss.resteasy.resteasy-jackson-provider"/>
<module name="org.jboss.resteasy.resteasy-jettison-provider"/>
<module name="org.jboss.resteasy.resteasy-jackson2-provider"/>
</exclusions>
<exclude-subsystems>
<subsystem name="logging"/>
<!--<subsystem name="resteasy"/>-->
</exclude-subsystems>
</deployment>
我有这样的错误
2017-01-12 10:59:27,659 ERROR [org.jboss.msc.service.fail] (ServerService Thread Pool -- 93) MSC000001: Failed to start service jboss.undertow.deployment.default-server.default-host./: org.jboss.msc.service.StartException in service jboss.undertow.deployment.default-server.default-host./: java.lang.NoClassDefFoundError: com/fasterxml/jackson/module/jaxb/JaxbAnnotationIntrospector
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:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
at org.jboss.threads.JBossThread.run(JBossThread.java:320)
Caused by: java.lang.NoClassDefFoundError: com/fasterxml/jackson/module/jaxb/JaxbAnnotationIntrospector
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Class.java:2671)
at java.lang.Class.getConstructors(Class.java:1651)
at org.jboss.resteasy.util.PickConstructor.pickSingletonConstructor(PickConstructor.java:30)
at org.jboss.resteasy.spi.ResteasyProviderFactory.createConstructorInjector(ResteasyProviderFactory.java:2252)
at org.jboss.resteasy.spi.ResteasyProviderFactory.createProviderInstance(ResteasyProviderFactory.java:2244)
at org.jboss.resteasy.spi.ResteasyProviderFactory.addContextResolver(ResteasyProviderFactory.java:1130)
at org.jboss.resteasy.spi.ResteasyProviderFactory.registerProvider(ResteasyProviderFactory.java:1667)
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.registerProvider(ResteasyDeployment.java:571)
at org.jboss.resteasy.spi.ResteasyDeployment.registration(ResteasyDeployment.java:347)
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.
答案 0 :(得分:1)
关于此错误消息:
java.lang.NoClassDefFoundError: Failed to link
com/fasterxml/jackson/jaxrs/base/ProviderBase
或:
java.lang.NoClassDefFoundError: com/fasterxml/jackson/jaxrs/base/ProviderBase
WildFly未加载/导出所有需要的库。您的 jboss-deployment-structure.xml 文件应如下所示:
<deployment>
<dependencies>
<module name="org.jboss.resteasy.resteasy-jackson2-provider" services="import"/>
<!-- This module contain the ProviderBase class: -->
<module name="com.fasterxml.jackson.jaxrs.jackson-jaxrs-json-provider" export="true"/>
</dependencies>
<exclusions>
<!-- Just to make sure these modules are not loaded -->
<module name="org.jboss.resteasy.resteasy-jackson-provider"/>
<module name="org.jboss.resteasy.resteasy-jettison-provider"/>
</exclusions>
</deployment>
答案 1 :(得分:0)
<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" />
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Expires" content="0" />
的 NoClassDefFoundError
表示模块JaxbAnnotationIntrospector
未指定为依赖项。
此模块包含课程jackson-module-jaxb-annotations
。
我认为依赖项应该添加为:
JaxbAnnotationIntrospector
根据需要指定导出。