0

I have two mapping patter /userdetails one for get request and one for post request.

It was working fine till I integrated Spring authorization into my project. Now I am getting below error any idea why this is happening?

My Two mappings are like this.

@RequestMapping(value = "/userdetails* ", method = RequestMethod.GET) 

@RequestMapping(value = "/userdetails*", method = RequestMethod.POST)

Please suggest any reason for this error.

Caused by: java.lang.IllegalStateException: Cannot map handler 'LoginController' to URL path [/userdetails]: There is already handler of type [class com.sample.user.controller.MyController] mapped.
    at org.springframework.web.servlet.handler.AbstractUrlHandlerMapping.registerHandler(AbstractUrlHandlerMapping.java:390)
    at org.springframework.web.servlet.handler.AbstractUrlHandlerMapping.registerHandler(AbstractUrlHandlerMapping.java:362)
    at org.springframework.web.servlet.handler.AbstractDetectingUrlHandlerMapping.detectHandlers(AbstractDetectingUrlHandlerMapping.java:82)
    at org.springframework.web.servlet.handler.AbstractDetectingUrlHandlerMapping.initApplicationContext(AbstractDetectingUrlHandlerMapping.java:58)
    at org.springframework.context.support.ApplicationObjectSupport.initApplicationContext(ApplicationObjectSupport.java:119)
    at org.springframework.web.context.support.WebApplicationObjectSupport.initApplicationContext(WebApplicationObjectSupport.java:72)
    at org.springframework.context.support.ApplicationObjectSupport.setApplicationContext(ApplicationObjectSupport.java:73)
    at org.springframework.context.support.ApplicationContextAwareProcessor.invokeAwareInterfaces(ApplicationContextAwareProcessor.java:117)
    at org.springframework.context.support.ApplicationContextAwareProcessor.postProcessBeforeInitialization(ApplicationContextAwareProcessor.java:92)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:396)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1475)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:521)
Sotirios Delimanolis
  • 274,122
  • 60
  • 696
  • 724
Adam
  • 727
  • 4
  • 11
  • 21
  • There must another handler that you aren't posting. The error is telling you there is already a handler method mapped for that type of request. – Sotirios Delimanolis Oct 01 '13 at 22:45
  • check this http://stackoverflow.com/questions/4802293/spring-beancreationexception-confusion-about-mapping – Foo Bar User Oct 01 '13 at 22:46
  • Which Spring version are you using and post the output of `mvn dependency:tree`. My guess you are using `mvc:annotation-driven />` and due to Spring Security you get the 3.0 version instead of the 3.1 (or up) version. – M. Deinum Oct 02 '13 at 12:39

1 Answers1

0

I faced similar kind of problem. I have defined the controller class with "@Controller" and also in the Spring-config.xml file as a bean and have injected the dependencies.

This was causing the problem. @Controller is defining the bean and again, the bean defined in the xml file is redefining the dependencies. I tried autowiring the dependency and removed it as a bean from the xml file. Then it worked.

Sanjeevan
  • 67
  • 5