找不到com.fasterxml.jackson.module.jaxb.JaxbAnnotationIntrospector-使用Swagger时 [英] com.fasterxml.jackson.module.jaxb.JaxbAnnotationIntrospector not found --- while using Swagger

查看:176
本文介绍了找不到com.fasterxml.jackson.module.jaxb.JaxbAnnotationIntrospector-使用Swagger时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我关于SO的第一篇文章,期望得到回报:-)

my first post on SO and expecting good stuff in return :-)

我开发了一个小型的Java Restful Services应用程序,并与Swagger集成.我有@Controller-> @Service-> @Repository体系结构.我已经在Glassfish(4.1.1)上进行了部署,当我使用Chrome的"Advanced Rest Client"时,我能够完美地发送和接收Rest调用(GET/POST等),但是当我使用Swagger时,它将引发以下异常在Controller返回正确的响应后."

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'.

我一直在努力通过更改maven条目版本,更改moxy jar,按照某些论坛中的建议删除felix等,似乎无济于事.

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.

这里有更多详细信息...

Here are more details ...

  StandardWrapperValve[com.xxx.config.ApplicationConfig]: Servlet.service() for servlet com.xxx.config.ApplicationConfig threw exception
java.lang.ClassNotFoundException: com.fasterxml.jackson.module.jaxb.JaxbAnnotationIntrospector not found by com.fasterxml.jackson.jaxrs.jackson-jaxrs-json-provider [130]
    at org.apache.felix.framework.BundleWiringImpl.findClassOrResourceByDelegation(BundleWiringImpl.java:1532)
    at org.apache.felix.framework.BundleWiringImpl.access$400(BundleWiringImpl.java:75)
    at org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.loadClass(BundleWiringImpl.java:1955)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)

代码:

@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

beans.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>

pom.xml中的wwagger条目

swagger entry in the pom.xml

<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.jackson</groupId>
                    <artifactId>jackson-mapper-asl</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>com.google.guava</groupId>
                    <artifactId>guava</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>com.fasterxml.jackson.module</groupId>
                    <artifactId>jackson-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.

推荐答案

堆栈跟踪中提到:java.lang.ClassNotFoundException: com.fasterxml.jackson.module.jaxb.JaxbAnnotationIntrospector not found by com.fasterxml.jackson.jaxrs.jackson-jaxrs-json-provider

并且您不包括JAXB注释模块:

and you are excluding the JAXB annotation module:

<exclusion>
   <groupId>com.fasterxml.jackson.module</groupId>
   <artifactId>jackson-module-jaxb-annotations</artifactId>
</exclusion>

排除表示依存关系未解决,因此您将获得ClassNotFoundException

The exclusion means a dependency is not resolved, and therefore you'll get the ClassNotFoundException

这篇关于找不到com.fasterxml.jackson.module.jaxb.JaxbAnnotationIntrospector-使用Swagger时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆