Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 461
user3006967 Avatar asked Jun 09 '15 16:06

user3006967


1 Answers

You are missing spring-cloud-starter-feign

like image 115
spencergibb Avatar answered Oct 24 '22 10:10

spencergibb