Using spring cloud feign causes java.lang.NoClassDefFoundError: feign/Logger

浪尽此生 提交于 2019-12-08 17:03:40

问题


I enabled my spring cloud for feignClients like this:

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

public class SpringCloudConfigClientApplication {
}

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)

My POM is

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

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

Thanks

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();
    }

and interface is:

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

The store entity is:

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;
    }
}

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])

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?

Thanks


回答1:


You are missing spring-cloud-starter-feign



来源:https://stackoverflow.com/questions/30737885/using-spring-cloud-feign-causes-java-lang-noclassdeffounderror-feign-logger

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!