0
Caused by: java.lang.IllegalStateException: Method findByApplicationName can only contain 1 method field. Found: []
    at feign.Util.checkState(Util.java:117) ~[feign-core-8.15.1.jar:8.15.1]
    at org.springframework.cloud.netflix.feign.support.SpringMvcContract.checkOne(SpringMvcContract.java:180) ~[spring-cloud-netflix-core-1.1.0.BUILD-SNAPSHOT.jar:1.1.0.BUILD-SNAPSHOT]
    at org.springframework.cloud.netflix.feign.support.SpringMvcContract.processAnnotationOnMethod(SpringMvcContract.java:143) ~[spring-cloud-netflix-core-1.1.0.BUILD-SNAPSHOT.jar:1.1.0.BUILD-SNAPSHOT]
    at feign.Contract$BaseContract.parseAndValidateMetadata(Contract.java:92) ~[feign-core-8.15.1.jar:8.15.1]
    at org.springframework.cloud.netflix.feign.support.SpringMvcContract.parseAndValidateMetadata(SpringMvcContract.java:100) ~[spring-cloud-netflix-core-1.1.0.BUILD-SNAPSHOT.jar:1.1.0.BUILD-SNAPSHOT]
    at feign.Contract$BaseContract.parseAndValidatateMetadata(Contract.java:61) ~[feign-core-8.15.1.jar:8.15.1]
    at feign.ReflectiveFeign$ParseHandlersByName.apply(ReflectiveFeign.java:140) ~[feign-core-8.15.1.jar:8.15.1]
    at feign.ReflectiveFeign.newInstance(ReflectiveFeign.java:58) ~[feign-core-8.15.1.jar:8.15.1]
    at feign.Feign$Builder.target(Feign.java:198) ~[feign-core-8.15.1.jar:8.15.1]
    at org.springframework.cloud.netflix.feign.FeignClientFactoryBean$DefaultTargeter.target(FeignClientFactoryBean.java:203) ~[spring-cloud-netflix-core-1.1.0.BUILD-SNAPSHOT.jar:1.1.0.BUILD-SNAPSHOT]
    at org.springframework.cloud.netflix.feign.FeignClientFactoryBean.loadBalance(FeignClientFactoryBean.java:153) ~[spring-cloud-netflix-core-1.1.0.BUILD-SNAPSHOT.jar:1.1.0.BUILD-SNAPSHOT]
    at org.springframework.cloud.netflix.feign.FeignClientFactoryBean.getObject(FeignClientFactoryBean.java:173) ~[spring-cloud-netflix-core-1.1.0.BUILD-SNAPSHOT.jar:1.1.0.BUILD-SNAPSHOT]
    at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:168) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
    ... 40 common frames omitted

How can I resolve this error?

halfer
  • 19,824
  • 17
  • 99
  • 186
Chintamani
  • 1,076
  • 7
  • 23
  • 47
  • Where is your source code? I doubt anyone will be able to help you with the information you provided. – print x div 0 Apr 05 '16 at 06:12
  • This looks like it was abandoned a long time ago without any action to requests for clarification. Voting to close for now. – halfer Jan 30 '18 at 00:02

3 Answers3

1

I think your feign client's method signature's @RequestMapping annotation is missing a method parameter e.g. GET or POST - see the code example below:

@FeignClient("client")
public interface MyClient {
  @RequestMapping(method = RequestMethod.GET, value = "/path-to-endpoint")
  MyResponse getMyResponse();
}
RobP
  • 706
  • 1
  • 8
  • 20
1

This type of issue will occur when Feign Client's RequestMapping has more than one value of primary mappings.

For instance

@FeignClient("PhotoClient")
public interface PhotoClient {
    @GetMapping(value = {"/photo/{photoId}", "/admin/photo/{photoId}"}, produces = APPLICATION_JSON_VALUE)
    ResponseEntity<PhotoDto> getPhoto(@PathVariable("photoId") String photoId);
}

In the above example GetMapping referring two primary mappings such as "/photo/{photoId}" and "/admin/photo/{photoId}".

If you initialize the above feign client using Spring boot's @EnableFeignClients as

@EnableFeignClients(basePackageClasses = {PhotoApi.class})

then following exception will be thrown

FactoryBean threw exception on object creation; nested exception is java.lang.IllegalStateException: Method getPhoto can only contain at most 1 value field. Found: [/photo/{photoId}, /admin/photo/{photoId}]

Unfortunately, there is no out-of-box configuration that exists to resolve this issue. Hence one simple solution is following below inheritance pattern:

Declaring the request methods in a common interface

public interface PhotoApi {
    @GetMapping(value = {"/photo/{photoId}"}, produces = APPLICATION_JSON_VALUE)
    ResponseEntity<PhotoDto> getPhoto(@PathVariable("photoId") String photoId);
}

Creating two feign-clients as per our need, the one for normal user and the other one for admin

@FeignClient("PhotoClient")
public interface PhotoClient extends PhotoApi{}
@FeignClient("AdminPhotoClient")
@RequestMapping({"/admin"})
interface AdminPhotoClient extends PhotoApi{}
Prasanth Rajendran
  • 4,570
  • 2
  • 42
  • 59
0

Observed feign client requires spring-cloud-dependencies as dependency management always. Try adding that as well