Spring MVC警告:没有找到带URI的HTTP请求的映射

时间:2012-12-11 17:22:45

标签: java spring-mvc spring-annotations

我的web.xml内容是:

<servlet>
        <servlet-name>springDispatcher</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>springDispatcher</servlet-name>
        <url-pattern>*.htm</url-pattern> <!-- Why not put / instead of *.html? -->
    </servlet-mapping>


    <!-- ContextLoader -->
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
            /WEB-INF/conf/applicationContext.xml
            /WEB-INF/conf/applicationContext-data.xml
            /WEB-INF/conf/applicationContext-service.xml

        </param-value>
    </context-param>

我的applicationContext.xml是:

<!-- Default ViewResolver -->
<bean
    class="org.springframework.web.servlet.view.InternalResourceViewResolver"
    p:prefix="/WEB-INF/jsp/" p:suffix=".jsp" />
<bean id="multipartResolver"
    class="org.springframework.web.multipart.commons.CommonsMultipartResolver" />

<context:annotation-config />

<context:component-scan base-package="com.lftechnology.controller" />

<!-- <bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" 
    /> -->

<bean
    class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" />

<bean class="com.lftechnology.controller.EmployeeController">
    <property name="employeeService" ref="employeeService" />
    <property name="departmentService" ref="departmentService"></property>
</bean>

最后控制器是:

@Controller
public class EmployeeController {

    EmployeeService employeeService;
    DepartmentService departmentService;

    //getters setters    

    @RequestMapping("/deleteEmployee.htm")
    public String deleteEmployee(HttpServletRequest request,
            HttpServletResponse response) throws Exception {
        //
        return "redirect:viewEmployee";
    }

    @RequestMapping("/viewEmployee.htm")
    public ModelAndView viewEmployee(HttpServletRequest request,
            HttpServletResponse response) throws Exception {

        Map<String, Object> model = new HashMap<String, Object>();
        //
        return new ModelAndView("viewEmployee", "model", model);
    }

}

例外:

 org.springframework.web.servlet.DispatcherServlet noHandlerFound
WARNING: No mapping found for HTTP request with URI [/springEmployeeAnotations/viewEmployee.htm] in DispatcherServlet with name 'springDispatcher' 

我不知道这段代码有什么问题。至少对我来说一切似乎都是正确的。尝试进入控制器的viewEmployee方法时会导致异常。有任何帮助吗?

2 个答案:

答案 0 :(得分:0)

试试这个:

<servlet-mapping>
<servlet-name>springDispatcher</servlet-name>
<url-pattern>/WEB-INF/jsp/*.htm </url-pattern>
</servlet-mapping>

答案 1 :(得分:-2)

您是否将控制器类映射到传入请求?

使用@RequestMapping(“/ springEmployeeAnotations”)

执行此操作
@Controller
@RequestMapping("/springEmployeeAnotations")
public class EmployeeController { .....

TP