@FeignClient with top level @RequestMapping annotation is also registered as Spring MVC handler
2018-01-17 11:02
549 查看
Generally the problem is that: when you annotate an @feignclient interface with @requestmapping annotation the handler will be also registered within Spring MVC.
In this test case: jmnarloch/spring-cloud-netflix@2d24bf6 this acctually causes the test to fail with error:
Due to duplicated Spring MVC - FeignClient mappings, but this how I found this issue.
Removing the top @requestmapping fixes the tests, but disallows some advances usages like interface inheritance and path overriding.
What about doing:
Example:
@FeignClient("localapp") @RequestMapping(value = "/users") public interface UsersClient extends CrudClient<User> { }
In this test case: jmnarloch/spring-cloud-netflix@2d24bf6 this acctually causes the test to fail with error:
Caused by: java.lang.IllegalStateException: Ambiguous mapping. Cannot map 'feignHttpClientTests$UserClient' method public abstract T org.springframework.cloud.netflix.feign.valid.FeignHttpClientTests$CrudClient.get(long) to {[/users/{id}],methods=[GET]}: There is already 'feignHttpClientTests.Application' bean method public java.lang.Object org.springframework.cloud.netflix.feign.valid.FeignHttpClientTests$Application.get(long) mapped. at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping$MappingRegistry.assertUniqueMethodMapping(AbstractHandlerMethodMapping.java:565) at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping$MappingRegistry.register(AbstractHandlerMethodMapping.java:529) at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.registerHandlerMethod(AbstractHandlerMethodMapping.java:252) at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.detectHandlerMethods(AbstractHandlerMethodMapping.java:223) at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.initHandlerMethods(AbstractHandlerMethodMapping.java:183) at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.afterPropertiesSet(AbstractHandlerMethodMapping.java:164) at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping.afterPropertiesSet(RequestMappingHandlerMapping.java:134) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1637) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1574) ... 44 more
Due to duplicated Spring MVC - FeignClient mappings, but this how I found this issue.
Removing the top @requestmapping fixes the tests, but disallows some advances usages like interface inheritance and path overriding.
What about doing:
@Configuration @ConditionalOnClass({Feign.class}) public class FeignMappingDefaultConfiguration { @Bean public WebMvcRegistrations feignWebRegistrations() { return new WebMvcRegistrationsAdapter() { @Override public RequestMappingHandlerMapping getRequestMappingHandlerMapping() { return new FeignFilterRequestMappingHandlerMapping(); } }; } private static class FeignFilterRequestMappingHandlerMapping extends RequestMappingHandlerMapping { @Override protected boolean isHandler(Class<?> beanType) { return super.isHandler(beanType) && (AnnotationUtils.findAnnotation(beanType, FeignClient.class) == null); } } }
相关文章推荐
- Spring MVC @RequestMapping Annotation Example with Controller, Methods, Headers, Params, @RequestParam, @PathVariable--转载
- Spring MVC PageNotFound.noHandlerFound No mapping found for HTTP request with URI
- Error creating bean with name 'org.springframework.web.servlet.mvc.method.annotation.RequestMappingH
- 解决spring mvc No mapping found for HTTP request with URI错误的三种方法
- Spring MVC No mapping found for HTTP request with URI
- SSM-----springMVC No mapping found for HTTP request with URI的问题
- mvc:annotation-driven 元素,HttpMessageConverter,RequestMappingHandlerAdapter
- spring mvc No mapping found for HTTP request with URI [] in DispatcherServlet
- No mapping found for HTTP request with URI [/springmvc/queryitems.action] in DispatcherServlet with
- springmvc No mapping found for HTTP request with URI in Dispatc
- Spring mvc No mapping found for HTTP request with URI
- No mapping found for HTTP request with URI [/SpringMVC/hello] in DispatcherServlet with name 'chapte
- springMVC No mapping found for HTTP request with URI
- spring mvc page not found no mapping found for http request with uri
- 警告: No mapping found for HTTP request with URI [/Springmvc/test] in DispatcherServlet with dispatche
- springMVC No mapping found for HTTP request with URI
- springMVC No mapping found for HTTP request with URI
- Spring Cloud ZooKeeper集成Feign的坑2,服务调用了一次后第二次调用就变成了500,错误:Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is com.n
- Spring 3 MVC No mapping found for HTTP request with URI (转)