使用Spring Cloud伪装会导致java.lang.NoClassDefFoundError:feign/Logger [英] Using spring cloud feign causes java.lang.NoClassDefFoundError: feign/Logger

查看:127
本文介绍了使用Spring Cloud伪装会导致java.lang.NoClassDefFoundError:feign/Logger的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为feignClients这样启用了我的Spring Cloud:

I enabled my spring cloud for feignClients like this:

@Configuration
@EnableAutoConfiguration
@RestController
@EnableEurekaClient
@EnableCircuitBreaker
@EnableFeignClients

public class SpringCloudConfigClientApplication {
}

但是当我添加enableFeignClients时,在编译过程中出现了此错误,

But as oon as I add enableFeignClients, I got this error during compilation,

java.lang.NoClassDefFoundError: feign/Logger
    at java.lang.Class.getDeclaredMethods0(Native Method)
    at java.lang.Class.privateGetDeclaredMethods(Class.java:2688)
    at java.lang.Class.getDeclaredMethods(Class.java:1962)

我的POM是

<parent>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-parent</artifactId>
        <version>1.0.0.RELEASE</version>
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <start-class>demo.SpringCloudConfigClientApplication</start-class>
        <java.version>1.7</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-eureka</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-config-server</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-hystrix</artifactId>
        </dependency>

    </dependencies>

为了解决伪装记录器问题,我还需要向POM添加什么其他依赖项?

In order to resolve feign logger issue, what other dependency do I need to add to the POM?

谢谢

谢谢@spencergibb,根据您的建议,在我更改pom之后它就起作用了.现在,我还有另一个使用FeignClient的问题.请参见以下内容:

Thank you @spencergibb, based on your suggestion, it worked after I change my pom. Now I have another issue for using FeignClient. Please see below:

@Autowired
    StoreClient storeClient;
    @RequestMapping("/stores")
    public List<Store> stores() {
        return storeClient.getStores();
    }

并且界面是:

@FeignClient("store")
public interface StoreClient {
    @RequestMapping(method = RequestMethod.GET, value = "/stores")
    List<Store> getStores();
}

商店实体为:

public class Store {

    private long id;
    private String name;
    private String zip;

    public Store(long id, String name, String zip) {
        this.id = id;
        this.name = name;
        this.zip = zip;
    }
}

现在,当我在URL中检索时,出现此错误,

Now when I retrieve in URL, I got this error,

ue Jun 09 15:30:10 PDT 2015
There was an unexpected error (type=Internal Server Error, status=500).
Could not read JSON: No suitable constructor found for type [simple type, class demo.entity.Store]: can not instantiate from JSON object (need to add/enable type information?) at [Source: java.io.PushbackInputStream@7db6c3dc; line: 1, column: 3] (through reference chain: java.util.ArrayList[0]); nested exception is com.fasterxml.jackson.databind.JsonMappingException: No suitable constructor found for type [simple type, class demo.entity.Store]: can not instantiate from JSON object (need to add/enable type information?) at [Source: java.io.PushbackInputStream@7db6c3dc; line: 1, column: 3] (through reference chain: java.util.ArrayList[0])

似乎这里出现的错误是检索列表无法转换为商店类. 因此,要使用FeignClient,我们需要包含的其他任何映射器将JSON转换为对象吗?

Seemed the error here is retrieved list can not be converted to store class. So in order to use FeignClient, any other mapper we need to include to convert JSON into objects?

谢谢

推荐答案

您丢失了spring-cloud-starter-feign

这篇关于使用Spring Cloud伪装会导致java.lang.NoClassDefFoundError:feign/Logger的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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