zhufeizzz commented on issue #1622: 跟SpringMVC共用的时候会存在路径冲突
URL: 
https://github.com/apache/servicecomb-java-chassis/issues/1622#issuecomment-604192165
 
 
   @liubao68 
你说的这个配置已经添加,问题的原因是SpringMVC会扫描到RestSchema类,并通过此方法判断`org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping#isHandler`,因为用到的RequestMapping注解,所以被扫描到。
   
   ```
        protected boolean isHandler(Class<?> beanType) {
                return (AnnotatedElementUtils.hasAnnotation(beanType, 
Controller.class) ||
                                AnnotatedElementUtils.hasAnnotation(beanType, 
RequestMapping.class));
        }
   ```
   
   完整错误日志如下:
   ```
   [2020-03-26 
10:20:35,366]-[]-[]-[main]-[org.springframework.boot.SpringApplication.reportFailure(SpringApplication.java:826)]-[ERROR]
 Application run failed
   org.springframework.beans.factory.BeanCreationException: Error creating bean 
with name 'requestMappingHandlerMapping' defined in class path resource 
[org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class]:
 Invocation of init method failed; nested exception is 
java.lang.IllegalStateException: Ambiguous mapping. Cannot map 'RepeatServiceA' 
method 
   com.huawei.mateinfo.demo.repeat.controller.a.RepeatService#hello()
   to {GET /rest/repeat-a/hello}: There is already 'repeatService' bean method
   com.huawei.mateinfo.demo.repeat.api.a.RepeatService#hello() mapped.
        at 
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1803)
 ~[spring-beans-5.2.1.RELEASE.jar:5.2.1.RELEASE]
        at 
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:595)
 ~[spring-beans-5.2.1.RELEASE.jar:5.2.1.RELEASE]
        at 
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:517)
 ~[spring-beans-5.2.1.RELEASE.jar:5.2.1.RELEASE]
        at 
org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:323)
 ~[spring-beans-5.2.1.RELEASE.jar:5.2.1.RELEASE]
        at 
org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
 ~[spring-beans-5.2.1.RELEASE.jar:5.2.1.RELEASE]
        at 
org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:321)
 ~[spring-beans-5.2.1.RELEASE.jar:5.2.1.RELEASE]
        at 
org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)
 ~[spring-beans-5.2.1.RELEASE.jar:5.2.1.RELEASE]
        at 
org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:879)
 ~[spring-beans-5.2.1.RELEASE.jar:5.2.1.RELEASE]
        at 
org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:878)
 ~[spring-context-5.2.1.RELEASE.jar:5.2.1.RELEASE]
        at 
org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:550)
 ~[spring-context-5.2.1.RELEASE.jar:5.2.1.RELEASE]
        at 
org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:141)
 ~[spring-boot-2.2.1.RELEASE.jar:2.2.1.RELEASE]
        at 
org.springframework.boot.SpringApplication.refresh(SpringApplication.java:747) 
[spring-boot-2.2.1.RELEASE.jar:2.2.1.RELEASE]
        at 
org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397)
 [spring-boot-2.2.1.RELEASE.jar:2.2.1.RELEASE]
        at 
org.springframework.boot.SpringApplication.run(SpringApplication.java:315) 
[spring-boot-2.2.1.RELEASE.jar:2.2.1.RELEASE]
        at 
org.springframework.boot.SpringApplication.run(SpringApplication.java:1226) 
[spring-boot-2.2.1.RELEASE.jar:2.2.1.RELEASE]
        at 
com.huawei.mateinfo.demo.SDKDemoApplication.main(SDKDemoApplication.java:16) 
[classes/:?]
   Caused by: java.lang.IllegalStateException: Ambiguous mapping. Cannot map 
'RepeatServiceA' method 
   com.huawei.mateinfo.demo.repeat.controller.a.RepeatService#hello()
   to {GET /rest/repeat-a/hello}: There is already 'repeatService' bean method
   com.huawei.mateinfo.demo.repeat.api.a.RepeatService#hello() mapped.
        at 
org.springframework.web.servlet.handler.AbstractHandlerMethodMapping$MappingRegistry.validateMethodMapping(AbstractHandlerMethodMapping.java:633)
 ~[spring-webmvc-5.2.1.RELEASE.jar:5.2.1.RELEASE]
        at 
org.springframework.web.servlet.handler.AbstractHandlerMethodMapping$MappingRegistry.register(AbstractHandlerMethodMapping.java:600)
 ~[spring-webmvc-5.2.1.RELEASE.jar:5.2.1.RELEASE]
        at 
org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.registerHandlerMethod(AbstractHandlerMethodMapping.java:318)
 ~[spring-webmvc-5.2.1.RELEASE.jar:5.2.1.RELEASE]
        at 
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping.registerHandlerMethod(RequestMappingHandlerMapping.java:350)
 ~[spring-webmvc-5.2.1.RELEASE.jar:5.2.1.RELEASE]
        at 
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping.registerHandlerMethod(RequestMappingHandlerMapping.java:67)
 ~[spring-webmvc-5.2.1.RELEASE.jar:5.2.1.RELEASE]
        at 
org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.lambda$detectHandlerMethods$1(AbstractHandlerMethodMapping.java:288)
 ~[spring-webmvc-5.2.1.RELEASE.jar:5.2.1.RELEASE]
        at java.util.LinkedHashMap.forEach(LinkedHashMap.java:684) 
~[?:1.8.0_211]
        at 
org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.detectHandlerMethods(AbstractHandlerMethodMapping.java:286)
 ~[spring-webmvc-5.2.1.RELEASE.jar:5.2.1.RELEASE]
        at 
org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.processCandidateBean(AbstractHandlerMethodMapping.java:258)
 ~[spring-webmvc-5.2.1.RELEASE.jar:5.2.1.RELEASE]
        at 
org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.initHandlerMethods(AbstractHandlerMethodMapping.java:217)
 ~[spring-webmvc-5.2.1.RELEASE.jar:5.2.1.RELEASE]
        at 
org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.afterPropertiesSet(AbstractHandlerMethodMapping.java:205)
 ~[spring-webmvc-5.2.1.RELEASE.jar:5.2.1.RELEASE]
        at 
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping.afterPropertiesSet(RequestMappingHandlerMapping.java:171)
 ~[spring-webmvc-5.2.1.RELEASE.jar:5.2.1.RELEASE]
        at 
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1862)
 ~[spring-beans-5.2.1.RELEASE.jar:5.2.1.RELEASE]
        at 
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1799)
 ~[spring-beans-5.2.1.RELEASE.jar:5.2.1.RELEASE]
        ... 15 more
   ```

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to