2020年3月26日 | Leave a comment 问题: Java Caused by: java.lang.IllegalStateException: Ambiguous mapping. Cannot map 'thelook.client.flipcoin.FlipcoinClient' method public abstract thelook.client.flipcoin.FlipcoinClient$AllocateResp thelook.client.flipcoin.FlipcoinClient.allocate(int,int) to {GET /v1/allocate, consumes [application/json;charset=UTF-8], produces [application/json;charset=UTF-8]}: There is already 'thelook.client.facade.FacadeClient' bean method public abstract thelook.client.facade.FacadeClient$AllocateResp thelook.client.facade.FacadeClient.allocate(java.lang.String,java.lang.String,java.lang.String) mapped. at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping$MappingRegistry.assertUniqueMethodMapping(AbstractHandlerMethodMapping.java:618) at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping$MappingRegistry.register(AbstractHandlerMethodMapping.java:586) at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.registerHandlerMethod(AbstractHandlerMethodMapping.java:312) at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.lambda$detectHandlerMethods$1(AbstractHandlerMethodMapping.java:282) at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping$$Lambda$1107.0000000059D7B820.accept(Unknown Source) at java.base/java.util.LinkedHashMap.forEach(LinkedHashMap.java:684) at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.detectHandlerMethods(AbstractHandlerMethodMapping.java:280) at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.processCandidateBean(AbstractHandlerMethodMapping.java:252) at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.initHandlerMethods(AbstractHandlerMethodMapping.java:211) at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.afterPropertiesSet(AbstractHandlerMethodMapping.java:199) at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping.afterPropertiesSet(RequestMappingHandlerMapping.java:164) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1837) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1774) ... 89 more 123456789101112131415161718 Caused by: java.lang.IllegalStateException: Ambiguous mapping. Cannot map 'thelook.client.flipcoin.FlipcoinClient' method public abstract thelook.client.flipcoin.FlipcoinClient$AllocateResp thelook.client.flipcoin.FlipcoinClient.allocate(int,int)to {GET /v1/allocate, consumes [application/json;charset=UTF-8], produces [application/json;charset=UTF-8]}: There is already 'thelook.client.facade.FacadeClient' bean methodpublic abstract thelook.client.facade.FacadeClient$AllocateResp thelook.client.facade.FacadeClient.allocate(java.lang.String,java.lang.String,java.lang.String) mapped. at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping$MappingRegistry.assertUniqueMethodMapping(AbstractHandlerMethodMapping.java:618) at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping$MappingRegistry.register(AbstractHandlerMethodMapping.java:586) at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.registerHandlerMethod(AbstractHandlerMethodMapping.java:312) at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.lambda$detectHandlerMethods$1(AbstractHandlerMethodMapping.java:282) at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping$$Lambda$1107.0000000059D7B820.accept(Unknown Source) at java.base/java.util.LinkedHashMap.forEach(LinkedHashMap.java:684) at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.detectHandlerMethods(AbstractHandlerMethodMapping.java:280) at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.processCandidateBean(AbstractHandlerMethodMapping.java:252) at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.initHandlerMethods(AbstractHandlerMethodMapping.java:211) at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.afterPropertiesSet(AbstractHandlerMethodMapping.java:199) at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping.afterPropertiesSet(RequestMappingHandlerMapping.java:164) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1837) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1774) ... 89 more ——- 解决: 不要在 FlipcoinClient & FacadeClient 上用 @RequestMapping ,可以调整到方法级别 分析: 问题是 FlipcoinClient & FacadeClient 中都有 @GetMapping(“/v1/allocate”) * allocate(…) exception堆栈中显示是 servlet mapping 冲突 ,问题是为什么会影响 servlet ? spring security 扫描了所有 @GetMapping 的方法? 参考: https://m.jb51.net/article/175683.htm https://stackoverflow.com/questions/55196238/feign-client-sub-domain-ambiguous-mapping?r=SearchResults