java com.fasterxml.jackson.module.jaxb.JaxbAnnotationIntrospector 未找到 --- 使用 Swagger 时
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/35538801/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
com.fasterxml.Hymanson.module.jaxb.JaxbAnnotationIntrospector not found --- while using Swagger
提问by rtnyc
my first post on SO and expecting good stuff in return :-)
我在 SO 上的第一篇文章并期待好东西的回报:-)
I have developed a small java restful services app and integrated with Swagger. I have @Controller -> @Service -> @Repository architecture. I have deployed on Glassfish (4.1.1), when I use Chrome's 'Advanced Rest Client', I am able to perfectly send and receive rest calls (GET/POST etc), but when I use Swagger, it throws the following exception 'after Controller returns the correct response'.
我开发了一个小型 java 宁静服务应用程序并与 Swagger 集成。我有 @Controller -> @Service -> @Repository 架构。我已经部署在 Glassfish (4.1.1) 上,当我使用 Chrome 的“高级休息客户端”时,我能够完美地发送和接收休息调用(GET/POST 等),但是当我使用 Swagger 时,它会抛出以下异常“在控制器返回正确的响应之后'。
I have been struggling with this by changing the maven entry versions, changing the moxy jar, delting felix as suggested in some forums etc, none seem to help.
我一直在通过更改 maven 入门版本、更改 moxy jar、按照某些论坛中的建议删除 felix 等来解决这个问题,但似乎没有任何帮助。
Here are more details ...
这里有更多细节...
Exception:
例外:
StandardWrapperValve[com.xxx.config.ApplicationConfig]: Servlet.service() for servlet com.xxx.config.ApplicationConfig threw exception
java.lang.ClassNotFoundException: com.fasterxml.Hymanson.module.jaxb.JaxbAnnotationIntrospector not found by com.fasterxml.Hymanson.jaxrs.Hymanson-jaxrs-json-provider [130]
at org.apache.felix.framework.BundleWiringImpl.findClassOrResourceByDelegation(BundleWiringImpl.java:1532)
at org.apache.felix.framework.BundleWiringImpl.access0(BundleWiringImpl.java:75)
at org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.loadClass(BundleWiringImpl.java:1955)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
Code:
代码:
@Controller
@Path("/document")
@Api(value = "/document", description = "Document Controller ")
public class DocumentController {
@Inject
DocumentService documentService;
@GET
@Path("/{id}")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Get Document.", notes = "Get Document Call")
@ApiResponses(value = { @ApiResponse(code = 200, message = "OK"),
@ApiResponse(code = 500, message = "Something wrong in Server") })
public DtoDocument getDocument(@PathParam("id") Integer docId) {
Document doc = documentService.getDocument(docId);
DtoDocument dto = toDto(doc);
return dto;
}
}
@Service
@Transactional
public class DocumentService {
@Inject
DocumentRepository repository;
public Document getDocument(Integer id) {
return repository.getDocumentById(id);
}
}
@Repository
public class DocumentRepository {
public static final String COLLECTION_NAME = "document";
@Inject
private MongoTemplate mongoTemplate;
public Document getDocumentById(Integer Id) {
Document doc = getMongoTemplate().findOne(Query.query(Criteria.where("id").is(Id)), Document.class, COLLECTION_NAME);
return doc;
}
}
@ApplicationPath("/rest")
public class ApplicationConfig extends Application {
@Override
@SuppressWarnings({ "unchecked", "rawtypes" })
public Set<Class<?>> getClasses() {
Set<Class<?>> resources = new java.util.HashSet();
resources.add(com.wordnik.swagger.jaxrs.listing.ApiListingResource.class);
resources.add(com.wordnik.swagger.jaxrs.listing.ApiDeclarationProvider.class);
resources.add(com.wordnik.swagger.jaxrs.listing.ApiListingResourceJSON.class);
resources.add(com.wordnik.swagger.jaxrs.listing.ResourceListingProvider.class);
addRestResourceClasses(resources);
return resources;
}
private void addRestResourceClasses(Set<Class<?>> resources) {
// Custom resources in the project (all restful services)
resources.add(com.xxx.web.rest.DocumentController.class);
}
}
beans.xml
bean.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd"
bean-discovery-mode="all">
</beans>
swagger entry in the pom.xml
pom.xml 中的 swagger 条目
<dependency>
<groupId>com.wordnik</groupId>
<artifactId>swagger-jersey-jaxrs_2.10</artifactId>
<version>1.3.13</version>
<exclusions>
<exclusion>
<groupId>com.sun.jersey.contribs</groupId>
<artifactId>jersey-spring</artifactId>
</exclusion>
<exclusion>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-client</artifactId>
</exclusion>
<exclusion>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-server</artifactId>
</exclusion>
<exclusion>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-core</artifactId>
</exclusion>
<exclusion>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-servlet</artifactId>
</exclusion>
<exclusion>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-multipart</artifactId>
</exclusion>
<exclusion>
<groupId>org.codehaus.Hymanson</groupId>
<artifactId>Hymanson-mapper-asl</artifactId>
</exclusion>
<exclusion>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</exclusion>
<exclusion>
<groupId>com.fasterxml.Hymanson.module</groupId>
<artifactId>Hymanson-module-jaxb-annotations</artifactId>
</exclusion>
</exclusions>
</dependency>
Appreciate if anyone can tell me what exactly is the issue ... its been a frustrating week & am stuck with this, not making any progress.
感谢有人能告诉我到底是什么问题......这是令人沮丧的一周,我坚持这一点,没有取得任何进展。
回答by beny23
The stack trace mentions: java.lang.ClassNotFoundException: com.fasterxml.Hymanson.module.jaxb.JaxbAnnotationIntrospector not found by com.fasterxml.Hymanson.jaxrs.Hymanson-jaxrs-json-provider
堆栈跟踪提到: java.lang.ClassNotFoundException: com.fasterxml.Hymanson.module.jaxb.JaxbAnnotationIntrospector not found by com.fasterxml.Hymanson.jaxrs.Hymanson-jaxrs-json-provider
and you are excluding the JAXB annotation module:
并且您不包括 JAXB 注释模块:
<exclusion>
<groupId>com.fasterxml.Hymanson.module</groupId>
<artifactId>Hymanson-module-jaxb-annotations</artifactId>
</exclusion>
The exclusion means a dependency is not resolved, and therefore you'll get the ClassNotFoundException
排除意味着未解决依赖项,因此您将获得 ClassNotFoundException
回答by Roberto Rodriguez
This worked for me:
这对我有用:
Steps: 1-Stop domain
步骤:一站域名
2-Remove content of this folder: Glassfish\glassfish\domains\DOMAIN_NAME\osgi-cache\felix
2-删除此文件夹的内容:Glassfish\glassfish\domains\DOMAIN_NAME\osgi-cache\felix
3-In this folder: C:\Glassfish\glassfish\modules Substitute Hymanson libraries by the 2.4.4 version:
3-在此文件夹中:C:\Glassfish\glassfish\modules 用 2.4.4 版本替换 Hymanson 库:
Hymanson-module-jaxb-annotations-2.4.4
Hymanson-module-jaxb-annotations-2.4.4
Hymanson-jaxrs-json-provider-2.4.4
Hymanson-jaxrs-json-provider-2.4.4
Hymanson-jaxrs-base-2.4.4
Hymanson-jaxrs-base-2.4.4
Hymanson-databind-2.4.4
Hyman逊-数据绑定-2.4.4
Hymanson-annotations-2.4.4
Hyman逊注释2.4.4
Hymanson-core-2.4.4
Hyman逊核心2.4.4
4-Start domain
4-起始域
I hope it helps :-)
我希望它有帮助:-)
回答by Ron
I don't know if this applies to 4.1.1 as well, but Glassfish 4.1 was shipped with old Hymanson version and that was the cause to the issue you bring above.
我不知道这是否也适用于 4.1.1,但 Glassfish 4.1 附带旧的 Hymanson 版本,这就是您在上面提出的问题的原因。
To solve it, you'd have to force Glassfish to load Hymanson 2.4.5 at least which is the minimum requirement for swagger-core. Upgrading Hymanson in GlassFish 4.1covers this procedure.
要解决它,您必须至少强制 Glassfish 加载 Hymanson 2.4.5,这是 swagger-core 的最低要求。在 GlassFish 4.1 中升级 Hymanson涵盖了此过程。
回答by RiTesh SrivasTav
Add 2 Dependency - it worked for me
添加 2 个依赖项 - 它对我有用
<dependency>
<groupId>com.fasterxml.Hymanson.module</groupId>
<artifactId>Hymanson-module-jaxb-annotations</artifactId>
<version>2.10.1</version>
</dependency>
<dependency>
<groupId>com.fasterxml.Hymanson.core</groupId>
<artifactId>Hymanson-databind</artifactId>
<exclusions>
<exclusion>
<groupId>com.fasterxml.Hymanson.module</groupId>
<artifactId>Hymanson-module-jaxb-annotations</artifactId>
</exclusion>
</exclusions>
</dependency>