简体   繁体   English

Spring Rest Web服务URL版本“。”不起作用

[英]Spring rest web services URL versioning “.” not working

I have this URI PRONTO_URI = "/api/v1.1/" with versioning 1.1 with mapping 我的URI PRONTO_URI =“ /api/v1.1/”,带有映射的版本1.1

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

but on deploying the application This is the stack trace. 但是在部署应用程序时,这是堆栈跟踪。

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 

Code of ProntoApiServiceController: Class has mapping /api/v1.1/ it is throwing error on using "." ProntoApiServiceController的代码:类具有映射/api/v1.1/,使用“。”时引发错误。 but is i replace v1.1 with v1 it is working fine 但是我用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;
    }
}

Seems your problem is that ProntoApiViewController and ProntoApiServiceController have the same request mapping and is a conflict. 似乎您的问题是ProntoApiViewControllerProntoApiServiceController具有相同的请求映射,并且是冲突的。

I created 2 controllers to verify this: 我创建了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");
     }
}

And i can confirm you that is working with the v1.1 value in the URL 我可以确认您正在使用URL中的v1.1值

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

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

I guess your problem is related with the duplication of URL names 我想您的问题与网址名称重复有关

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM