2016-07-13 55 views
0

我有这个URI PRONTO_URI =“/api/v1.1/”与版本1.1 与映射Spring rest web服务URL版本控制“。”不工作

@RestController 
@RequestMapping(ProntoRestURIConstants.PRONTO_URI) 
@Scope("request") 
public class ProntoBuildApiController{ 
... 
} 

但上部署应用程序这是堆栈跟踪。

13:02:56,215 ERROR [org.springframework.web.context.ContextLoader] (MSC service thread 1-1) Context initialization failed: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping#0' defined in ServletContext resource [/WEB-INF/context/web-context.xml]: Initialization of bean failed; nested exception is java.lang.IllegalStateException: Cannot map handler 'prontoApiViewController' to URL path [/api/1.1/]: There is already handler of type [class com.nsn.pronto.api.controller.ProntoApiServiceController] mapped. 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:532) [spring-beans-3.2.0.RELEASE.jar:3.2.0.RELEASE] 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:461) [spring-beans-3.2.0.RELEASE.jar:3.2.0.RELEASE] 
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295) [spring-beans-3.2.0.RELEASE.jar:3.2.0.RELEASE] 
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223) [spring-beans-3.2.0.RELEASE.jar:3.2.0.RELEASE] 
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292) [spring-beans-3.2.0.RELEASE.jar:3.2.0.RELEASE] 
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194) [spring-beans-3.2.0.RELEASE.jar:3.2.0.RELEASE] 
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:607) [spring-beans-3.2.0.RELEASE.jar:3.2.0.RELEASE] 
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932) [spring-context-3.2.0.RELEASE.jar:3.2.0.RELEASE] 
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479) [spring-context-3.2.0.RELEASE.jar:3.2.0.RELEASE] 
    at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:383) [spring-web-3.2.0.RELEASE.jar:3.2.0.RELEASE] 
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:283) [spring-web-3.2.0.RELEASE.jar:3.2.0.RELEASE] 
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:112) [spring-web-3.2.0.RELEASE.jar:3.2.0.RELEASE] 
    at org.apache.catalina.core.StandardContext.contextListenerStart(StandardContext.java:3392) [jbossweb-7.0.13.Final.jar:] 
    at org.apache.catalina.core.StandardContext.start(StandardContext.java:3850) [jbossweb-7.0.13.Final.jar:] 
    at org.jboss.as.web.deployment.WebDeploymentService.start(WebDeploymentService.java:90) [jboss-as-web-7.1.1.Final.jar:7.1.1.Final] 
    at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811) 
    at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746) 
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) [rt.jar:1.7.0_17] 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [rt.jar:1.7.0_17] 
    at java.lang.Thread.run(Unknown Source) [rt.jar:1.7.0_17] 
Caused by: java.lang.IllegalStateException: Cannot map handler 'prontoApiViewController' to URL path [/api/1.1/]: There is already handler of type [class com.nsn.pronto.api.controller.ProntoApiServiceController] mapped. 
    at 
ProntoApiServiceController的

代码: “” 类具有映射/api/v1.1/它使用投掷错误但我与V1这是工作的罚款代替V1.1

@RestController 
    @RequestMapping(value = ProntoRestURIConstants.PRONTO_URI) 
    @Scope("request") 
    public class ProntoApiServiceController extends RestApiBaseController { 

@GET 
    @RequestMapping(value = ProntoRestURIConstants.FETCH_API_VIEWS_BY_PR , headers = "Accept=application/json; charset=UTF-8") 
    public List<com.nsn.pronto.api.domain.ProblemReport> fetchApiViewByProblemReport(@Context HttpServletRequest request) { 

     LOGGER.info(" *** fetchApiViewByProblemReport - ENTRY *******"); 
     String path; 
     List<com.nsn.pronto.api.domain.ProblemReport> lstProblemReport = null; 
     try { 
      path = URLDecoder.decode(request.getQueryString() , "UTF-8"); 

      lstProblemReport = getApiProblemReportBusinessService().fetchApiPRByQueryString(path); 
     } catch(UnsupportedEncodingException e) { 
      LOGGER.error(e); 
     } 

     LOGGER.info(" *** fetchApiViewByProblemReport - EXIT *******"); 
     return lstProblemReport; 
    } 
} 
+0

请分享你的ProntoApiServiceController代码。 – Sampada

+0

@Sampada代码已添加。 ProntoApiServiceController的代码:类有映射/api/v1.1/它使用“。”时抛出错误。但是我用v1替换v1.1它工作正常 –

+0

你不能使用相同的映射注释2个类。 – Sampada

回答

0

看来你的问题是,ProntoApiViewControllerProntoApiServiceController具有相同的请求映射和冲突。

我创建了2个控制器来验证这一点:

@Controller 
@RequestMapping("/v1.1/service") 
public class ServiceController { 

    @RequestMapping(method=RequestMethod.GET, value="/one") 
    public void method(){ 
     System.out.println("Method one from ServiceController"); 
    } 
} 

@Controller 
@RequestMapping("/v1.1/api") 
public class ApiController { 

    @RequestMapping(method=RequestMethod.GET, value="/one") 
    public void method(){ 
     System.out.println("Method one from ApiController"); 
    } 
} 

,我可以确认你正在与V1.1值在URL

http://localhost:9090/v1.1/service/one

http://localhost:9090/v1.1/api/one

我猜你r问题与URL名称重复有关

+0

这些URI映射正在工作,如果我不使用它们之间的点(。),但如果我有映射/api/v1.1/ Class使用“。”时抛出错误。但是我用v1替换v1.1它工作正常 –

+0

@manishthapliyal并且你在两个控制器中用v1替换v1.1? – cralfaro

+0

@ralfaro我正在使用两个控制器共享的常量 –