基于Spring mvc注释的控制器RequestMappingHandlerMapping有什么问题?

时间:2013-04-22 03:33:51

标签: java spring spring-mvc

我将我的一个应用程序从Spring工具套件IDE移植到纯Eclipse Java EE IDE。 在这个过程中,我正在重命名一些包并改为基于Maven。然后所有控制器都不再工作了。

我认为注释控制器发现似乎已被打破。没有映射网址注册Spring。

有谁知道问题是什么?

我从我的STS(工作)收集旧日志,它的工作和喜欢

> 2013-04-21 22:43:05,622 [Thread-1] DEBUG
> org.springframework.beans.factory.support.DefaultListableBeanFactory -
> Finished creating instance of bean
> 'org.springframework.web.servlet.handler.MappedInterceptor#2'
> 2013-04-21 22:43:05,623 [Thread-1] DEBUG
> org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping
> - Looking for request mappings in application context: WebApplicationContext for namespace 'HelloSpringroo2-servlet': startup
> date [Sun Apr 21 22:43:05 EDT 2013]; parent: Root
> WebApplicationContext 2013-04-21 22:43:05,653 [Thread-1] INFO 
> org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping
> - Mapped "{[/account/create],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}"
> onto public java.lang.String
> com.hellospringroo.controllers.AccountController.createAccountActionDisplay(org.springframework.ui.Model)
> 2013-04-21 22:43:05,653 [Thread-1] INFO 
> org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping
> - Mapped "{[/account/view/{account_Id}],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}"
> onto public java.lang.String
> com.hellospringroo.controllers.AccountController.viewAccountActionDisplay(int,org.springframework.ui.Model)
> throws java.lang.Exception

然后我从Eclipse(问题一)收集日志

> 2013-04-21 22:48:04,900 [http-bio-8080-exec-3] DEBUG
> org.springframework.web.servlet.DispatcherServlet - DispatcherServlet
> with name 'Education' processing GET request for [/Education/]
> 2013-04-21 22:48:04,901 [http-bio-8080-exec-3] DEBUG
> org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping
> - Looking up handler method for path / 2013-04-21 22:48:04,901 [http-bio-8080-exec-3] DEBUG
> org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping
> - Did not find handler method for [/] 2013-04-21 22:48:04,904 [http-bio-8080-exec-3] DEBUG
> org.springframework.web.servlet.handler.SimpleUrlHandlerMapping -
> Mapping [/] to HandlerExecutionChain with handler
> [org.springframework.web.servlet.mvc.ParameterizableViewController@54bbb2d0]
> and 1 interceptor 2013-04-21 22:48:04,905 [http-bio-8080-exec-3] DEBUG
> org.springframework.web.servlet.DispatcherServlet - Last-Modified
> value for [/Education/] is: -1 2013-04-21 22:48:04,914
> [http-bio-8080-exec-3] DEBUG
> org.springframework.beans.factory.support.DefaultListableBeanFactory -
> Invoking afterPropertiesSet() on bean with name 'index'

2 个答案:

答案 0 :(得分:2)

您:

<context:component-scan base-package="old.package.name" />

现在应该是

<context:component-scan base-package="new.package.name" />

答案 1 :(得分:0)

你有没有机会将Spring罐子的版本从3.0改为3.2或者从3.2.2等改为3.2.M1?

我有类似的问题(不完全相同),但这对我有用。

旧版本有@Controller("\abc")处理程序方法@RequestMapping("\pqr")。处理的网址是\abc\pqr

新版本没有用,我不得不改成它 @Controller @RequestMapping ("\abc")然后处理程序方法映射与上面相同。 或者在处理程序方法上使用完整的url映射,而不是在控制器级别,例如在方法级别上使用@RequestMapping("\abc\pqr")