Spring mvc 4.0+freemarker抛javax.servlet.ServletException: Could not resolve view with name

Spring 4.0+Spring mvc4.0+Freemarker集成项目,一切的东西都配好了,但是出现javax.servlet.ServletException: Could not resolve view with name 的问题。这里先留一个伏笔,先看看我的集成配置:

web.xml


    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
    http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
    
        index.jsp
    

    
    
        log4jConfigLocation
        classpath:com/autoclub/config/log4j.properties
   

   
        log4jRefreshInterval
        6000
   

   
     
        org.springframework.web.util.Log4jConfigListener
     

  


    
    
        org.springframework.web.context.ContextLoaderListener
    

    
    
    
        contextConfigLocation
        classpath:com/autoclub/config/spring.xml
    

    
    
    
        dispatcher1
        org.springframework.web.servlet.DispatcherServlet
        
            contextConfigLocation
            classpath*:com/autoclub/config/spring-mvc.xml
        

        1
    

    
        dispatcher1
        /
   

   
    
        characterEncodingFilter
        org.springframework.web.filter.CharacterEncodingFilter
        
            encoding
            UTF-8
        

    

    
        characterEncodingFilter
        /*
    



Spring.xml


        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
        xmlns:aop="http://www.springframework.org/schema/aop"  
        xmlns:tx="http://www.springframework.org/schema/tx"
        xmlns:mvc="http://www.springframework.org/schema/mvc"  
        xmlns:context="http://www.springframework.org/schema/context"  
        xsi:schemaLocation="http://www.springframework.org/schema/beans
            http://www.springframework.org/schema/beans/spring-beans-4.0.xsd  
            http://www.springframework.org/schema/aop
            http://www.springframework.org/schema/aop/spring-aop-4.0.xsd  
            http://www.springframework.org/schema/tx
            http://www.springframework.org/schema/tx/spring-tx-4.0.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-context-3.2.xsd">

      
     
        
    
    
    
    
    

    
    
        
        
        
        
    


    
    

    
    
        
    

    
    
    
       
           
           
           
           
       

    

    
    
    
        
        
    


    
    
        
               
              
                
                       
                     
                classpath:com/autoclub/domain/mapper/**/*.xml            
            
        
        

    


    
    
       
    

    
    
    
        
    

    
    
 


Spring-mvc.xml


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

    
   
        
        
            
                10
                zh_CN
                yyyy-MM-dd
                yyyy-MM-dd
                #.##
                utf-8
            

        

    

    
    
     
        
        
        
        
        
        
        
    

    
    
   


测试例子Controller

package com.autoclub.controller.admin;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.portlet.ModelAndView;



@Controller
@RequestMapping("/admin/user")
public class UserController {
    
    @RequestMapping("/test2")
    public ModelAndView initCreate(){
        ModelAndView modelAndView = new ModelAndView();
        System.out.println("111in1111");
        modelAndView.addObject("user","小陈");
        modelAndView.setViewName("admin/registerUser");
        return modelAndView;
    }
    
    @RequestMapping("/test")
    public String test(ModelMap map){
        System.out.println("222in22221");
        return "admin/registerUser";
    }
}

一切都那么的美好,觉得没有什么问题。然后IE上敲地址:http://localhost:8080/AUTOCLUB/admin/user/test2

后台直接抛Spring mvc 4.0+freemarker抛javax.servlet.ServletException: Could not resolve view with name_第1张图片

找了一个早上,把公司所有的牛人都叫过来看了一篇,都觉得配置没有问题,方法也是这样写的。好吧,最后没有办法了,好吧,回归最基础,怀疑是否方法写得有问题,检查 ModelAndView对象的引入,发现引入的是spring-webmvc-portlet-4.0.0.RELEASE.jar包下的org.springframework.web.portlet.ModelAndView,出现这个错误,暂时不知道为什么这个增强包提供的对象就会有问题,换回org.springframework.web.servlet.ModelAndView引入后 问题解决。如果有朋友知道原因 请给我留言,谢谢。

你可能感兴趣的:(Spring)