Spring3 mvc集成Tiles2

用的spring3.05和titles2.2.1(spring3.0.5配tiles2.2.2会报错:java.lang.ClassNotFoundException: org.apache.tiles.startup.BasicTilesInitializer,原因是tiles-core2.2.2中该类已经deprecated了)。
关键配置是servlet-context.xml和tiles.xml。
servlet-conext.xml的内容如下:

<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:beans="http://www.springframework.org/schema/beans"
xsi:schemaLocation="
        http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-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/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">

<!-- DispatcherServlet Context: defines this servlet's request-processing infrastructure -->

<!-- Enables the Spring MVC @Controller programming model -->
<annotation-driven />
<context:component-scan base-package="com.lshoo.tiles" />

<!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources directory -->
<resources mapping="/resources/**" location="/resources/" />

<!-- <beans:import resource="controllers.xml" /> -->

<beans:bean id="viewResolver"
class="org.springframework.web.servlet.view.UrlBasedViewResolver">
<beans:property name="viewClass">
<beans:value>
org.springframework.web.servlet.view.tiles2.TilesView
</beans:value>
</beans:property>
</beans:bean>
<beans:bean id="tilesConfigurer"
class="org.springframework.web.servlet.view.tiles2.TilesConfigurer">
<beans:property name="definitions">
<beans:list>
<beans:value>/WEB-INF/tiles.xml</beans:value>
</beans:list>
</beans:property>
<beans:property name="preparerFactoryClass" value="org.springframework.web.servlet.view.tiles2.SpringBeanPreparerFactory" />

</beans:bean>



</beans:beans>
tiles.xml内容如下:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE tiles-definitions PUBLIC
       "-//Apache Software Foundation//DTD Tiles Configuration 2.0//EN"
       "http://tiles.apache.org/dtds/tiles-config_2_0.dtd">
<tiles-definitions>
    <definition name="mainTemplate"
        template="/WEB-INF/views/template.jsp">
        <put-attribute name="title" value="" />
        <put-attribute name="header" value="/WEB-INF/views/header.jsp" />
        <put-attribute name="menu" value="/WEB-INF/views/menu.jsp" />
        <put-attribute name="body" value="" />
        <put-attribute name="footer" value="/WEB-INF/views/footer.jsp" />
    </definition>

    <definition name="*" extends="mainTemplate">
        <put-attribute name="title" value="Contact Manager" type="string"/>
        <put-attribute name="body" value="/WEB-INF/views/{1}.jsp" />
    </definition>

</tiles-definitions>
在tiles2.xml中使用通配符,结合spring3mvc的RESTful风格,自动区配。

你可能感兴趣的:(apache,spring,mvc,xml,servlet)