spring(1)- spring-servlet.xml 配置Freemarker

spring-servlet.xml

<?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:cxf="http://cxf.apache.org/core"
	xmlns:p="http://cxf.apache.org/policy" xmlns:ss="http://www.springframework.org/schema/security"
	xmlns:jaxws="http://cxf.apache.org/jaxws" xmlns:jee="http://www.springframework.org/schema/jee"
	xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
	xmlns:context="http://www.springframework.org/schema/context"
	xmlns:mvc="http://www.springframework.org/schema/mvc"
	xmlns:util="http://www.springframework.org/schema/util"
	xmlns:ehcache="http://ehcache-spring-annotations.googlecode.com/svn/schema/ehcache-spring"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd 
   	http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd 
   	http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd 
   	http://cxf.apache.org/policy http://cxf.apache.org/schemas/policy.xsd
   	http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
   	http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd
   	http://cxf.apache.org/bindings/soap http://cxf.apache.org/schemas/configuration/soap.xsd 
   	http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security.xsd 
   	http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
   	http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
   	http://ehcache-spring-annotations.googlecode.com/svn/schema/ehcache-spring
    http://ehcache-spring-annotations.googlecode.com/svn/schema/ehcache-spring/ehcache-spring-1.1.xsd
	http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd
   	http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">

<mvc:annotation-driven/>

	<context:component-scan base-package="com.java.*" />
	
	<bean id="freemarkerResolver"
		class="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver">
		<!--<property name="cache" value="true"/> -->
		<property name="order" value="1" />
		<property name="suffix" value=".ftl" />
		<property name="requestContextAttribute" value="request" />
		<property name="exposeSpringMacroHelpers" value="true" />
		<property name="exposeRequestAttributes" value="true" />
		<property name="exposeSessionAttributes" value="true" />
		<property name="allowSessionOverride" value="true" />
		<property name="contentType" value="text/html;charset=utf-8" />
		<property name="viewClass"
			value="org.springframework.web.servlet.view.freemarker.FreeMarkerView" />
	</bean>
	
    <bean id="htmlResolver"
		class="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver">
		<!--<property name="cache" value="true"/> -->
		<property name="order" value="1" />
		<property name="suffix" value=".html" />
		<property name="requestContextAttribute" value="request" />
		<property name="exposeSpringMacroHelpers" value="true" />
		<property name="exposeRequestAttributes" value="true" />
		<property name="exposeSessionAttributes" value="true" />
		<property name="allowSessionOverride" value="true" />
		<property name="contentType" value="text/html;charset=utf-8" />
		<property name="viewClass"
			value="org.springframework.web.servlet.view.freemarker.FreeMarkerView" />
	</bean>
	
		<!-- 将list强制转换成json和xml -->
	<bean
		class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
		<property name="messageConverters">
			<list>
				<bean id="mappingJacksonHttpMessageConverter"
					class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter">
					<property name="supportedMediaTypes">
						<list>
							<value>text/html;charset=UTF-8</value>
						</list>
					</property>
				</bean>
				<bean
					class="org.springframework.http.converter.StringHttpMessageConverter">
					<property name="supportedMediaTypes">
						<list>
							<value>text/html;charset=UTF-8</value>
						</list>
					</property>
				</bean>
				<!--可以增加其他数据类型,请参考spring的API -->
			</list>
		</property>
	</bean>

	<!-- 文件上传支持 -->
	<bean id="multipartResolver"
		class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
		<property name="defaultEncoding" value="utf-8"></property>
		<property name="maxUploadSize">
			<value>32505856</value>
		</property>
		<property name="maxInMemorySize">
			<value>4096</value>
		</property>
	</bean>


	<bean id="webPropertyConfig"
		class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
		<property name="locations">
			<list>
				<value>classpath:conf/main-setting-web.properties</value>
				<value>classpath:conf/prop/setting-web-$[ent.type].properties</value>
			</list>
		</property>
		<property name="placeholderPrefix" value="@{" />
		<property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE" />
	</bean>

	<bean id="freemarkerConfig"
		class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer">
		<description>Required for Freemarker to work in web tier</description>
		<property name="configuration" ref="freemarkerConfiguration" />
	</bean>

	<bean id="freemarkerConfiguration"
		class="org.springframework.ui.freemarker.FreeMarkerConfigurationFactoryBean">
		<description>Using the Config directly so we can use it outside the
			web tier
		</description>
		<property name="templateLoaderPaths">
			<list>
				<value>/WEB-INF/ftl/</value>
			</list>
		</property>
		<property name="configLocation">
			<value>classpath:conf/freemarker.properties</value>
		</property>
		<!--全局变量部分 -->
		<property name="freemarkerVariables">
			<map>
				<entry key="xml_escape" value-ref="fmXmlEscape" />
				<entry key="html_escape" value-ref="fmHtmlEscape" />
				<entry key="base" value="@{base}" />
				<entry key="appVersion" value="@{appVersion}" />
			</map>
		</property>
		<property name="defaultEncoding" value="utf-8" />
	</bean>

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

	<bean class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor" />

	<mvc:interceptors>

		<!-- 国际化拦截器配置 -->
		<!-- <mvc:interceptor>
		  <mvc:mapping path="/**"/>
		  <bean id="localeChangeInterceptor" class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor" />
		</mvc:interceptor> -->
		
		<mvc:interceptor>
			<mvc:mapping path="/*/profile/**" />
			<bean id="DOSUrlInterceptor" class="com.java.web.interceptor.DOSUrlInterceptor" />
		</mvc:interceptor>
	</mvc:interceptors>
	
	
	<bean id="localeChangeInterceptor" class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor" />
	
	
	<!-- 国际化配置 -->
	 <bean id="cookieLocaleResolver" class="org.springframework.web.servlet.i18n.CookieLocaleResolver">
        <property name="defaultLocale" value="zh_CN"/>  
        <property name="cookieName" value="language"/>  
        <property name="cookieMaxAge" value="3600"/> 
	 </bean>
	  
	
	<bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
        <property name="basename" value="classpath:i18n/messages"/>
        <property name="useCodeAsDefaultMessage" value="true"/>
    </bean>
	
	
	
	
	
	
	
	
</beans>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
提供的源码资源涵盖了安卓应用、小程序、Python应用和Java应用等多个领域,每个领域都包含了丰富的实例和项目。这些源码都是基于各自平台的最新技术和标准编写,确保了在对应环境下能够无缝运行。同时,源码中配备了详细的注释和文档,帮助用户快速理解代码结构和实现逻辑。 适用人群: 这些源码资源特别适合大学生群体。无论你是计算机相关专业的学生,还是对其他领域编程感兴趣的学生,这些资源都能为你提供宝贵的学习和实践机会。通过学习和运行这些源码,你可以掌握各平台开发的基础知识,提升编程能力和项目实战经验。 使用场景及目标: 在学习阶段,你可以利用这些源码资源进行课程实践、课外项目或毕业设计。通过分析和运行源码,你将深入了解各平台开发的技术细节和最佳实践,逐步培养起自己的项目开发和问题解决能力。此外,在求职或创业过程中,具备跨平台开发能力的大学生将更具竞争力。 其他说明: 为了确保源码资源的可运行性和易用性,特别注意了以下几点:首先,每份源码都提供了详细的运行环境和依赖说明,确保用户能够轻松搭建起开发环境;其次,源码中的注释和文档都非常完善,方便用户快速上手和理解代码;最后,我会定期更新这些源码资源,以适应各平台技术的最新发展和市场需求。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值