关于spring和springmvc的xml自动扫描配置问题

今天在尝试搭建一下SSM框架的时候,在webapp目录下有一个MyJsp.jsp。部署到服务器后,能够正常访问,然后我去写了一个页面,通过controller进行访问,但是死活不出来,而且提示一个404页面。

关于spring和springmvc的xml自动扫描配置问题_第1张图片

我看了下控制台DEBUG的输出:No mapping found for HTTP request with URI [/Monitor/login.action] in DispatcherServlet with name 'springmvc',说没有找到这个映射,

DEBUG [http-apr-8080-exec-3] - Bound request context to thread: org.apache.catalina.connector.RequestFacade@5f2421d0
DEBUG [http-apr-8080-exec-3] - DispatcherServlet with name 'springmvc' processing GET request for [/Monitor/login.action]
DEBUG [http-apr-8080-exec-3] - Testing handler map [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping@13fa3263] in DispatcherServlet with name 'springmvc'
DEBUG [http-apr-8080-exec-3] - Looking up handler method for path /login.action
DEBUG [http-apr-8080-exec-3] - Did not find handler method for [/login.action]
DEBUG [http-apr-8080-exec-3] - Testing handler map [org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping@30facaa5] in DispatcherServlet with name 'springmvc'
DEBUG [http-apr-8080-exec-3] - No handler mapping found for [/login.action]
 WARN [http-apr-8080-exec-3] - No mapping found for HTTP request with URI [/Monitor/login.action] in DispatcherServlet with name 'springmvc'
DEBUG [http-apr-8080-exec-3] - Cleared thread-bound request context: org.apache.catalina.connector.RequestFacade@5f2421d0
DEBUG [http-apr-8080-exec-3] - Successfully completed request
DEBUG [http-apr-8080-exec-3] - Publishing event in WebApplicationContext for namespace 'springmvc-servlet': ServletRequestHandledEvent: url=[/Monitor/login.action]; client=[127.0.0.1]; method=[GET]; servlet=[springmvc]; session=[9358E9BE84EAA25B3232FC982B81825F]; user=[null]; time=[27ms]; status=[OK]
DEBUG [http-apr-8080-exec-3] - Publishing event in Root WebApplicationContext: ServletRequestHandledEvent: url=[/Monitor/login.action]; client=[127.0.0.1]; method=[GET]; servlet=[springmvc]; session=[9358E9BE84EAA25B3232FC982B81825F]; user=[null]; time=[27ms]; status=[OK]

然后我就百度了一阵,没有找到解决方法。然后我就仔细看了一下DEBUG的输出,好像发现是因为springmvc的xml里没有找到controller的映射的问题。仔细想了下是不是因为我只在applicationContext.xml里面配置了自动扫描没有再springmvc.xml里没有自动扫描的原因。原配置如下:

springmvc.xml:




	

	
		
		
	

applicationContext.xml:




	
	

然后我就在springmvc.xml里面加了一个专门用来扫描存放controller的包:


然后再访问controller就好了。

我的个人博客:点击进入我的个人博客

你可能感兴趣的:(学习记录)