[GitHub] [servicecomb-java-chassis] zhufeizzz commented on issue #1622: 跟SpringMVC共用的时候会存在路径冲突
zhufeizzz commented on issue #1622: 跟SpringMVC共用的时候会存在路径冲突 URL: https://github.com/apache/servicecomb-java-chassis/issues/1622#issuecomment-604199014 @liubao68 因为CSE和SpringMVC是分别编写的,很难控制命名冲突,比如同样一个用户创建的接口,CSE和SpringMVC可能都叫/user/create,目前的规避措施是SpringMVC全都加上一层前缀,如:/web/user/create,但体验就比较差了。 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
[GitHub] [servicecomb-java-chassis] zhufeizzz commented on issue #1622: 跟SpringMVC共用的时候会存在路径冲突
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)
[GitHub] [servicecomb-java-chassis] zhufeizzz commented on issue #1622: 跟SpringMVC共用的时候会存在路径冲突
zhufeizzz commented on issue #1622: 跟SpringMVC共用的时候会存在路径冲突 URL: https://github.com/apache/servicecomb-java-chassis/issues/1622#issuecomment-595207392 SpringMVC本身可以根据Bean名称前缀进行排除,CSE是不是可以考虑生成Bean的时候按这个规范来生成啊 `org.springframework.web.servlet.handler.AbstractHandlerMethodMapping#SCOPED_TARGET_NAME_PREFIX` 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