添加mvc名称空间时,Spring-MVC不起作用

时间:2013-03-31 18:22:21

标签: java spring spring-mvc

我的MVC项目在没有mvc名称空间的情况下完美运行,但在添加它时......

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    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
        http://www.springframework.org/schema/mvc
        http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
        ">

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

    <mvc:resources mapping="/resources/**" location="/resources/" /> 

    <bean id="templateResolver"
        class="org.thymeleaf.templateresolver.ServletContextTemplateResolver">
        <property name="prefix" value="/WEB-INF/pages/" />
        <property name="suffix" value=".html" />
        <property name="templateMode" value="HTML5" />
        <property name="cacheable" value="false" />
    </bean>

    <bean id="templateEngine" class="org.thymeleaf.spring3.SpringTemplateEngine">
        <property name="templateResolver" ref="templateResolver" />
    </bean>

    <bean class="org.thymeleaf.spring3.view.ThymeleafViewResolver">
        <property name="templateEngine" ref="templateEngine" />
        <property name="characterEncoding" value="UTF-8" />
    </bean>

</beans>

我得到404,日志显示为No handler mapping found for [/node/manage]。对于jsp来说是一样的,所以不是Thimeleaf问题。 我很确定它是xsd版本的东西。我使用Spring 3.2。

2 个答案:

答案 0 :(得分:1)

添加

解决
<mvc:annotation-driven/> 

显然使用

时会覆盖默认行为
<mvc:resources mapping="/resources/**" location="/resources/" /> 

答案 1 :(得分:0)

感谢您对&#39;注释&#39;的评论。

小心使用注释驱动,两天前我的项目不能使用资源目录,因为我将spring 3.2.8与hibernate 4.2.6混合使用。他们使用自己的注释集。 混合这两种技术,在servlet配置中使用两个注释标签:

<mvc:annotation-driven/> in controller and views configuration
<mvc:resources mapping=" ...
...

<tx:annotation-driven/> in transacional or hibernate configuration

资源映射仅适用于此标记组合,适用于不同的anotation技术。

再见。