web.xml
Archetype Created Web Application
contextConfigLocation
/WEB-INF/config/spring/spring-ctx.xml
springmvc
org.springframework.web.servlet.DispatcherServlet
contextConfigLocation
/WEB-INF/config/spring/spring-mvc.xml
1
springmvc
/*
org.springframework.web.context.ContextLoaderListener
spring-ctx.xml
spring-mvc
controller
package com.prs.dps;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@Controller
public class Test {
@RequestMapping(value = "/toindex",method = RequestMethod.GET)
public String toIndex(){
return "index";
}
}
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
这个项目里有两个容器。
Spring application context和Spring webapplication context。分别对应两个配置文件
applicationContext.xml和{servletName}-servlet.xml。他们之间并不会共享管理的对象。
通过你的配置文件可以看出只有根容器
Spring application进行了扫描,Spring MVC的容器(webapplication context)中没有管理的对象。而
Spring 根容器(application context)不具备处理映射的功能,无法处理请求映射。所以配置应该这样。
修改spring-mvc.xml如下:
改为这个试下:
堕天使008的解决方法是对的
·
DispatcherServlet加载Web组件的bean·
ContextLoaderListener加载中间层和数据层的bean组件补充下
· 建议把spring mvc项目中controller和service组件的包分开
· 建议题主在
spring-mvc.xml中加上静态资源处理器如果还没有解决问题,推荐阅读 spring mvc helloworld example 实例比较简明清楚,也可以下载实例项目