用Idea配置的时候每次都有各种各样的错误,这次是tomcat启动后自动跳转到index页面没有问题,但是手动跳转到target下访问时,报500错误

复制代码
@Controller
public class TargetController {

    @RequestMapping("/target")
    public ModelAndView show(){
        System.out.println("目标资源执行。。。。");
        ModelAndView modelAndView=new ModelAndView();
        modelAndView.addObject("name","zyw");
        modelAndView.setViewName("index");
        return modelAndView;
    }
}
复制代码

 

 经过百度,得知可能是spring-mvc配置时的命名空间依赖不完整,

解决后的命名空间:

复制代码
<beans xmlns="http://www.springframework.org/schema/beans"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xmlns:context="http://www.springframework.org/schema/context"
           xmlns:mvc="http://www.springframework.org/schema/mvc"
           xsi:schemaLocation="http://www.springframework.org/schema/beans
       http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
    http://www.springframework.org/schema/mvc
    http://www.springframework.org/schema/mvc/spring-mvc-4.2.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context-4.2.xsd">
复制代码

原本错误的命名空间:

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/mvc  http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/context  http://www.springframework.org/schema/context/spring-conntext.xsd">

不可思议,我就少了个4.2的版本号???