次のように、feignClients のスプリング クラウドを有効にしました。
@Configuration
@EnableAutoConfiguration
@RestController
@EnableEurekaClient
@EnableCircuitBreaker
@EnableFeignClients
public class SpringCloudConfigClientApplication {
}
しかし、enableFeignClients を追加するとすぐに、コンパイル中にこのエラーが発生しました。
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 に追加する必要がありますか?
ありがとう
@spencergibb に感謝します。あなたの提案に基づいて、pom を変更した後に機能しました。今、FeignClient の使用に関する別の問題があります。下記を参照してください:
@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で取得すると、このエラーが発生しました。
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 をオブジェクトに変換するために含める必要がある他のマッパーはありますか?
ありがとう