0

我有两种映射模式 /userdetails 一种用于获取请求,一种用于发布请求。

在我将 Spring 授权集成到我的项目中之前,它工作正常。现在我遇到错误了,知道为什么会这样吗?

我的两个映射是这样的。

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

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

请提出此错误的任何原因。

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)
4

1 回答 1

0

我遇到了类似的问题。我已经用“@Controller”定义了控制器类,并且在 Spring-config.xml 文件中定义了一个 bean 并注入了依赖项。

这是造成问题的原因。@Controller 正在定义 bean,xml 文件中定义的 bean 正在重新定义依赖项。我尝试自动装配依赖项并将其作为 bean 从 xml 文件中删除。然后它起作用了。

于 2015-06-21T05:38:54.607 回答