You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by GitBox <gi...@apache.org> on 2020/03/05 12:34:18 UTC

[GitHub] [servicecomb-java-chassis] zhufeizzz opened a new issue #1622: 跟SpringMVC共用的时候会存在路径冲突

zhufeizzz opened a new issue #1622: 跟SpringMVC共用的时候会存在路径冲突
URL: https://github.com/apache/servicecomb-java-chassis/issues/1622
 
 
   ```
   @RestSchema(schemaId = "RepeatServiceA")
   @RequestMapping(path = "/rest/repeat-a")
   public class RepeatService 
   
   @RestController("RepeatServiceB")
   @RequestMapping(path = "/rest/repeat-a")
   public class RepeatService {
   ```
   比如下面这两种,因路径冲突SpringMVC会报“Ambiguous mapping”异常。即使CSE和SpringMVC分别声明了独立的根路径。这种问题有什么解决建议吗?
   ```
   spring:
     mvc:
       servlet:
         path: /ui
   servicecomb: 
       servlet:
         urlPattern: /cse/*
   ```

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [servicecomb-java-chassis] liubao68 commented on issue #1622: 跟SpringMVC共用的时候会存在路径冲突

Posted by GitBox <gi...@apache.org>.
liubao68 commented on issue #1622: 跟SpringMVC共用的时候会存在路径冲突
URL: https://github.com/apache/servicecomb-java-chassis/issues/1622#issuecomment-604197570
 
 
   按照你说的, 应该是 spring MVC 自己加载了下面的两个类作为 Controller。 我发的配置项只控制 java-chassis 不加载 `@RestController`。 需要像个办法让 spring MVC 不加载 `@RestSchema` , 否则只能避免名字冲突了。 
   
   ```
   @RestSchema(schemaId = "RepeatServiceA")
   @RequestMapping(path = "/rest/repeat-a")
   public class RepeatService 
   
   @RestController("RepeatServiceB")
   @RequestMapping(path = "/rest/repeat-a")
   public class RepeatService 
   ```
   
   BWT: 实际应用场景需要 RepeatServiceA 和 RepeatServiceB 有一样的 url 吗? 感觉这个是个错误。 是不是 "/rest/repeat-b"? 

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [servicecomb-java-chassis] liubao68 edited a comment on issue #1622: 跟SpringMVC共用的时候会存在路径冲突

Posted by GitBox <gi...@apache.org>.
liubao68 edited a comment on issue #1622: 跟SpringMVC共用的时候会存在路径冲突
URL: https://github.com/apache/servicecomb-java-chassis/issues/1622#issuecomment-604177277
 
 
   这个异常没碰到过,可能需要具体看看是什么情况下,哪个组件抛出来的。 也可以加上`servicecomb.provider.rest.scanRestController` 试试。 

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [servicecomb-java-chassis] liubao68 commented on issue #1622: 跟SpringMVC共用的时候会存在路径冲突

Posted by GitBox <gi...@apache.org>.
liubao68 commented on issue #1622: 跟SpringMVC共用的时候会存在路径冲突
URL: https://github.com/apache/servicecomb-java-chassis/issues/1622#issuecomment-604177277
 
 
   这个异常没碰到过,可能需要具体看看是申请情况下,哪个组件抛出来的。 也加上`servicecomb.provider.rest.scanRestController` 试试。 

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [servicecomb-java-chassis] liubao68 edited a comment on issue #1622: 跟SpringMVC共用的时候会存在路径冲突

Posted by GitBox <gi...@apache.org>.
liubao68 edited a comment on issue #1622: 跟SpringMVC共用的时候会存在路径冲突
URL: https://github.com/apache/servicecomb-java-chassis/issues/1622#issuecomment-604177277
 
 
   这个异常没碰到过,可能需要具体看看是什么情况下,哪个组件抛出来的。 也加上`servicecomb.provider.rest.scanRestController` 试试。 

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [servicecomb-java-chassis] zhufeizzz commented on issue #1622: 跟SpringMVC共用的时候会存在路径冲突

Posted by GitBox <gi...@apache.org>.
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:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [servicecomb-java-chassis] zhufeizzz commented on issue #1622: 跟SpringMVC共用的时候会存在路径冲突

Posted by GitBox <gi...@apache.org>.
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:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [servicecomb-java-chassis] liubao68 edited a comment on issue #1622: 跟SpringMVC共用的时候会存在路径冲突

Posted by GitBox <gi...@apache.org>.
liubao68 edited a comment on issue #1622: 跟SpringMVC共用的时候会存在路径冲突
URL: https://github.com/apache/servicecomb-java-chassis/issues/1622#issuecomment-604177277
 
 
   这个异常没碰到过,可能需要具体看看是什么情况下,哪个组件抛出来的, 可以提供下详细的错误堆栈。 也可以加上`servicecomb.provider.rest.scanRestController=false` 试试。 

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [servicecomb-java-chassis] zhufeizzz commented on issue #1622: 跟SpringMVC共用的时候会存在路径冲突

Posted by GitBox <gi...@apache.org>.
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:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [servicecomb-java-chassis] zhufeizzz removed a comment on issue #1622: 跟SpringMVC共用的时候会存在路径冲突

Posted by GitBox <gi...@apache.org>.
zhufeizzz removed a comment 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:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [servicecomb-java-chassis] liubao68 edited a comment on issue #1622: 跟SpringMVC共用的时候会存在路径冲突

Posted by GitBox <gi...@apache.org>.
liubao68 edited a comment on issue #1622: 跟SpringMVC共用的时候会存在路径冲突
URL: https://github.com/apache/servicecomb-java-chassis/issues/1622#issuecomment-604177277
 
 
   这个异常没碰到过,可能需要具体看看是什么情况下,哪个组件抛出来的, 可以提供下详细的错误堆栈。 也可以加上`servicecomb.provider.rest.scanRestController` 试试。 

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services