xml Spring MVC 4 XML配置文件

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了xml Spring MVC 4 XML配置文件相关的知识,希望对你有一定的参考价值。

<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns="http://java.sun.com/xml/ns/javaee"
	xsi:schemaLocation="
		http://java.sun.com/xml/ns/javaee
		http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
		version="2.5">
    
    <display-name>java8-dev-webapp</display-name>
	<description>java8-dev-webapp</description>
	
	<context-param>
		<param-name>contextConfigLocation</param-name>
		<param-value>/WEB-INF/appconfig-root.xml</param-value>
	</context-param>

    <servlet>
        <servlet-name>mvc-dispatcher</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value></param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>mvc-dispatcher</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>
    
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
</web-app>
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns:context="http://www.springframework.org/schema/context"
	xmlns="http://www.springframework.org/schema/beans"
	xsi:schemaLocation="
		http://www.springframework.org/schema/beans
		http://www.springframework.org/schema/beans/spring-beans.xsd
		http://www.springframework.org/schema/context 
		http://www.springframework.org/schema/context/spring-context.xsd">
	<import resource="appconfig-mvc.xml"/>
	
	<context:component-scan base-package="io.github.gczarnocki.*"/>
	<context:property-placeholder location="classpath:application.properties"/>
</beans>
<?xml version="1.0" encoding="UTF-8" ?>
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns:mvc="http://www.springframework.org/schema/mvc"
	xmlns="http://www.springframework.org/schema/beans"
	xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="
       http://www.springframework.org/schema/mvc
       http://www.springframework.org/schema/mvc/spring-mvc.xsd
       http://www.springframework.org/schema/beans
       http://www.springframework.org/schema/beans/spring-beans.xsd">
	
	<mvc:annotation-driven/>
	
	<mvc:resources mapping="/resources/**" location="/resources/"/>
	<mvc:resources mapping="/webjars/**" location="classpath:/META-INF/resources/webjars/"/>
	
	<bean id="templateResolver" class="org.thymeleaf.templateresolver.ServletContextTemplateResolver">
		<property name="prefix" value="/WEB-INF/templates/"/>
        <property name="suffix" value=".html"/>
        <property name="templateMode" value="HTML"/>
        <property name="cacheable" value="false"/>
        <property name="characterEncoding" value="UTF-8"/>
	</bean>
    
    <bean id="templateEngine" class="org.thymeleaf.spring4.SpringTemplateEngine">
        <property name="templateResolver" ref="templateResolver"/>
        <property name="enableSpringELCompiler" value="true"/>
    </bean>
    
    <bean class="org.thymeleaf.spring4.view.ThymeleafViewResolver">
    	<property name="templateEngine" ref="templateEngine"/>
    </bean>
</beans>

以上是关于xml Spring MVC 4 XML配置文件的主要内容,如果未能解决你的问题,请参考以下文章

spring mvc 配置(xml配置详解)

Spring MVC中,applicationContext.xml [ServletName]-servlet.xml配置文件在web.xml中的配置详解...

spring mvc mybatis 整合用配置web.xml文件吗

Spring MVC 配置文件dispatcher-servlet.xml 文件详解

新建项目web.xml,spring-mvc.xml简单配置问题

spring mvc +ibatis 怎样配置自动加载多个sqlmap.xml文件