2015-06-09 21 views
9

tôi kích hoạt đám mây mùa xuân của tôi cho feignClients như thế này:Sử dụng mùa xuân đám mây giả vờ gây java.lang.NoClassDefFoundError: giả vờ/Logger

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

public class SpringCloudConfigClientApplication { 
} 

Nhưng khi oon như tôi thêm enableFeignClients, tôi đã nhận lỗi này trong thời gian biên soạn,

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 của tôi là

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

để giải quyết vấn đề logger giả vờ, những gì depende khác ncy tôi cần phải thêm vào POM?

Cảm ơn

Cảm ơn bạn @spencergibb, dựa trên đề xuất của bạn, nó hoạt động sau khi tôi thay đổi pom. Bây giờ tôi có một vấn đề khác để sử dụng FeignClient. Xin vui lòng xem bên dưới:

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

và giao diện là:

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

Thực thể cửa hàng là:

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

Bây giờ khi tôi lấy trong URL, tôi đã nhận lỗi này,

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: [email protected]; 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: [email protected]; line: 1, column: 3] (through reference chain: java.util.ArrayList[0]) 

Dường như lỗi ở đây là danh sách được truy xuất không thể chuyển đổi thành lớp lưu trữ. Vì vậy, để sử dụng FeignClient, bất kỳ trình ánh xạ nào khác chúng tôi cần đưa vào để chuyển đổi JSON thành các đối tượng?

Cảm ơn

+0

trả lời bản thân mình, phải đặt một constructor rỗng mặc định trong classs tổ chức để thực hiện các mapper làm việc. Cảm ơn – user3006967

Trả lời

21

Bạn đang thiếu spring-cloud-starter-feign

+0

Cảm ơn bạn, @spencergibb, bạn đã đúng. Bạn có thể giúp cho biết làm thế nào để ánh xạ từ JSON vào các đối tượng? Dường như FeignClient không làm điều này. – user3006967

+0

Đối tượng của bạn có công cụ xây dựng no-arg công khai không? – spencergibb

Các vấn đề liên quan