我有这个URI PRONTO_URI =“/ api/v1.1/”,版本为1.1 与映射
@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 :(得分:0)
似乎你的问题是 ProntoApiViewController 和 ProntoApiServiceController 具有相同的请求映射并且是冲突。
我创建了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");
}
}
我可以确认您正在使用URL中的v1.1值
我猜你的问题与网址重复有关