`

Springmvc中多视图解析器解析 配置(fremarker +jsp)

阅读更多
直接上配置文件, 讨论群:172429747

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

	<!-- 启动扫描所有的controller -->
	<context:component-scan base-package="com.inspur.web.ctrl">
    	<context:include-filter type="annotation" expression="org.springframework.stereotype.Controller" /> 
 	    <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Service" /> 
    </context:component-scan>
    
	<!-- 支持注解 -->
	<mvc:annotation-driven />
	<!-- 静态资源不走springMVC 过滤器 -->
	<mvc:resources location="/resources/css/**" mapping="/css/**" />
	<mvc:resources location="/resources/js/**" mapping="/js/**" />
	<mvc:resources location="/resources/html/**" mapping="/html/**" />
	<mvc:resources location="/resources/images/**" mapping="/images/**" />
	<mvc:resources location="/resources/swf/**" mapping="/swf/**" />
	
	<!-- 拦截器 -->
	<mvc:interceptors>  
      <bean class="com.inspur.util.spring3.interceptor.InspurInterceptor" />  
    </mvc:interceptors>

	<!--通用视图解析器 -->
	<bean id="viewResolverCommon"
		class="org.springframework.web.servlet.view.InternalResourceViewResolver">
		<property name="viewClass"
			value="org.springframework.web.servlet.view.InternalResourceView" />
		<property name="prefix" value="/WEB-INF/jsp/" />
		<property name="suffix" value=".jsp" />
		<property name="order" value="1" />
	</bean>

		<!-- 配置freeMarker视图解析器 -->
	<bean class="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver">
<!-- 		<property name="viewClass" -->
<!-- 			value="org.springframework.web.servlet.view.freemarker.FreeMarkerView" /> -->
<property name="viewClass"
			value="com.inspur.util.freemarker.view.NativeFreemarkerView" />
			
		<property name="exposeRequestAttributes" value="true" />
		<property name="allowSessionOverride" value="true"/>
		<property name="exposeSessionAttributes" value="true" />
		<property name="exposeSpringMacroHelpers" value="true" />
		<property name="contentType" value="text/html; charset=utf-8" />
		<property name="cache" value="true" />
		<property name="prefix" value="" />
		<property name="suffix" value=".ftl" />
		<property name="order" value="0" />
	</bean>
	
	<bean class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
		<property name="ignoreAcceptHeader" value="true" />
		<property name="defaultContentType" value="text/html" />
		<property name="mediaTypes">
			<map>
				<entry key="json" value="application/json" />
			</map>
		</property>
		<property name="favorParameter" value="false" />
		<property name="viewResolvers">
			<list>
				<bean class="org.springframework.web.servlet.view.BeanNameViewResolver" />
			</list>
		</property>
		<property name="defaultViews">
			<list>
				<bean
					class="org.springframework.web.servlet.view.json.MappingJacksonJsonView" />
			</list>
		</property>
	</bean>

	<bean id="fmXmlEscape" class="freemarker.template.utility.XmlEscape" />

	<!-- 配置freeMarker的模板路径 -->
	<bean id="freemarkerConfig"
		class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer">
		<property name="freemarkerSettings" ref="freemarkerConfiguration" />
		<property name="templateLoaderPaths">
			<list>
				<value>WEB-INF/ftl/</value>
				<value>classpath:/templates/</value>
			</list>
		</property>
		<property name="freemarkerVariables">
			<map>
				<entry key="xml_escape" value-ref="fmXmlEscape" />
			</map>
		</property>
		<property name="preferFileSystemAccess" value="false" />
	</bean>

	
	<!--spring MVC 上传配置 -->
	<bean id="multipartResolver"
		class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
		<!-- one of the properties available; the maximum file size in bytes -->
		<property name="maxUploadSize" value="11000000" />
	</bean>

</beans>
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics