0

I have this URI PRONTO_URI = "/api/v1.1/" with versioning 1.1 with mapping

@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 "." but is i replace v1.1 with v1 it is working fine

 @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;
    }
}
manish Prasad
  • 636
  • 6
  • 16
  • please share code for your ProntoApiServiceController as well. – Sampada Jul 13 '16 at 07:52
  • 1
    @Sampada code added . Code of ProntoApiServiceController: Class has mapping /api/v1.1/ it is throwing error on using "." but is i replace v1.1 with v1 it is working fine – manish Prasad Jul 13 '16 at 08:09
  • You cannot annotate 2 classes with the same mapping. – Sampada Jul 13 '16 at 08:30
  • 1
    @Sampada This mapping are working correctly, if i use dot(.) in between the URL then it is throwing error. – manish Prasad Jul 13 '16 at 09:44
  • Spring MVC and Security has known issues with dots in the path. I look up the bug #s later. – Adam Gent Jul 13 '16 at 11:55
  • @Adam Gent can you please elaborate your comment? – manish Prasad Jul 13 '16 at 12:30
  • @manishthapliyal Here is the Spring Security one: http://stackoverflow.com/questions/20590794/spring-security-trailing-slashes-and-dots-in-urls . I know there is an MVC issue as well (I believe for certain containers) but I am having trouble looking for it. I just don't recommend putting "." in your paths but instead use underscores or minus signs. – Adam Gent Jul 13 '16 at 12:33

1 Answers1

0

Seems your problem is that ProntoApiViewController and ProntoApiServiceController have the same request mapping and is a conflict.

I created 2 controllers to verify this:

@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

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

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

I guess your problem is related with the duplication of URL names

cralfaro
  • 5,822
  • 3
  • 20
  • 30
  • 1
    these URI mapping is working if i don't use dot(.) between them , but if i have Class with mapping /api/v1.1/ it is throwing error on using "." but is i replace v1.1 with v1 it is working fine – manish Prasad Jul 13 '16 at 09:42
  • 1
    @manishthapliyal and you replace v1.1 by v1 in both controllers? – cralfaro Jul 13 '16 at 10:03
  • 1
    @ralfaro i am using a constant which is shared by both controllers – manish Prasad Jul 13 '16 at 10:14
  • 1
    @manishthapliyal review the complete URL value, I tried a URL con dots in the path and works correctly. Spring-boot – cralfaro Jul 13 '16 at 10:21
  • 1
    Not working i changed the request mapping for ProntoApiServiceController with "/api/v1.1/problemReport/" – manish Prasad Jul 13 '16 at 10:30
  • Could you paste the code of this 2 controllers? ProntoApiViewController and ProntoApiServiceController – cralfaro Jul 13 '16 at 10:32
  • 1
    @RestController @RequestMapping(value = ProntoRestURIConstants.PRONTO_URI_PR) @Scope("request") public class ProntoApiServiceController extends RestApiBaseController { ... } – manish Prasad Jul 13 '16 at 10:34
  • 1
    @RestController @RequestMapping(ProntoRestURIConstants.PRONTO_URI) @Scope("request") public class ProntoApiViewController extends RestApiBaseController { ... } – manish Prasad Jul 13 '16 at 10:34
  • 1
    public static final String PRONTO_URI = "/api/latest/"; public static final String PRONTO_URI_PR = "/api/1.1/problemReport/"; – manish Prasad Jul 13 '16 at 10:35
  • @manishthapliyal still working for me correctly, what do you have in your RestApiBaseController? – cralfaro Jul 13 '16 at 10:47
  • 1
    the problem is not related to duplicated uri it is related to dot(.) in request mapping – manish Prasad Jul 13 '16 at 10:48
  • If you are using some pathVariable have a look here http://stackoverflow.com/questions/2079299/trying-to-create-rest-ful-urls-with-mulitple-dots-in-the-filename-part-sprin – cralfaro Jul 13 '16 at 10:49
  • 1
    thanks for help , but I am having problem in class level request mapping and not with method level mapping. – manish Prasad Jul 13 '16 at 11:45