<?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:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:p="http://www.springframework.org/schema/p"
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/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd">
<!-- 启用spring mvc注解 -->
<context:annotation-config/>
<!-- 设置使用注解的类所在包 -->
<context:component-scan base-package="com.**.dao"/>
<context:component-scan base-package="com.**.service.impl"/>
<context:component-scan base-package="com.**.action"/>
<!-- 关闭URL地址扩展名支持 -->
<bean id="contentNegotiationManager" class="org.springframework.web.accept.ContentNegotiationManagerFactoryBean">
<property name="favorPathExtension" value="false" />
</bean>
<!-- 消息转换器 -->
<mvc:annotation-driven content-negotiation-manager="contentNegotiationManager">
<mvc:message-converters register-defaults="true">
<!-- String对象解析 -->
<bean class="org.springframework.http.converter.StringHttpMessageConverter">
<property name="supportedMediaTypes" value="text/html;charset=UTF-8"/>
</bean>
<!-- JSON对象解析 -->
<bean class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter">
<property name="supportedMediaTypes" value="application/json;charset=UTF-8"/>
</bean>
</mvc:message-converters>
</mvc:annotation-driven>
<!-- 对模型视图名称的解析,即在模型视图名称添加前后缀 -->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver" p:prefix="/" p:suffix=".jsp"/>
<!-- 加载自定义配置文件 -->
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:config/properties/dbtype.properties</value>
<value>classpath:config/properties/mail.properties</value>
</list>
</property>
</bean>
<!-- 配置关系型数据库连接池 (dbcp) -->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<!-- 数据源配置 -->
<property name="driverClassName" value="${driverClassName}"/>
<property name="url" value="${url}"/>
<property name="username" value="${username}"/>
<property name="password" value="${password}"/>
<property name="maxActive" value="200"/>
<property name="maxIdle" value="100"/>
<property name="minIdle" value="20"/>
<property name="maxWait" value="30000"/>
<!-- 防止连接超时 -->
<property name="validationQuery" value="SELECT 1" />
<property name="testOnBorrow" value="true"/>
</bean>
<!-- 配置Mybatis -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<!-- 自动扫描并加载某个目录下的多个SQL映射的XML文件,省掉Configuration.xml里的手工配置 -->
<property name="mapperLocations" value="classpath:config/mybatis/${dbType}/mapping/*.xml" />
<property name="dataSource" ref="dataSource" />
</bean>
<!-- 配置扫描器 -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<!-- 扫描某个目录下的包以及它的子包下的所有映射接口类 -->
<property name="basePackage" value="com.**.dao"/>
<!-- 如有多个数据源则此处需要指定:“sqlSessionFactoryBeanName” -->
<!--<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"/>-->
<!-- 配置该参数则只注册使用了annotationClass注解标记的DAO接口 -->
<!--<property name="annotationClass" value="org.springframework.stereotype.Repository"/> -->
</bean>
<!-- 配置Spring的事务管理器
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
</bean>
-->
<!-- 拦截器方式配置事物
<tx:advice id="transactionAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="add*" propagation="REQUIRED" />
<tx:method name="append*" propagation="REQUIRED" />
<tx:method name="insert*" propagation="REQUIRED" />
<tx:method name="save*" propagation="REQUIRED" />
<tx:method name="update*" propagation="REQUIRED" />
<tx:method name="modify*" propagation="REQUIRED" />
<tx:method name="edit*" propagation="REQUIRED" />
<tx:method name="delete*" propagation="REQUIRED" />
<tx:method name="remove*" propagation="REQUIRED" />
<tx:method name="repair" propagation="REQUIRED" />
<tx:method name="delAndRepair" propagation="REQUIRED" />
<tx:method name="get*" propagation="SUPPORTS" />
<tx:method name="find*" propagation="SUPPORTS" />
<tx:method name="load*" propagation="SUPPORTS" />
<tx:method name="search*" propagation="SUPPORTS" />
<tx:method name="datagrid*" propagation="SUPPORTS" />
<tx:method name="*" propagation="SUPPORTS" />
</tx:attributes>
</tx:advice>
<aop:config>
<aop:pointcut id="transactionPointcut" expression="execution(* com.kuangchi.service.impl..*.*(..))" />
<aop:advisor pointcut-ref="transactionPointcut" advice-ref="transactionAdvice" />
</aop:config>
-->
<!-- JavaMail服务 -->
<bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
<!-- 邮箱服务器配置 -->
<property name="host" value="${mail.smtp.host}" />
<property name="port" value="${mail.smtp.port}" />
<property name="username" value="${mail.smtp.username}" />
<property name="password" value="${mail.smtp.password}" />
<property name="javaMailProperties">
<props>
<!-- 发送模式 debug -->
<prop key="mail.debug">true</prop>
<!-- 开启SMTP服务器验证 -->
<prop key="mail.smtp.auth">${mail.smtp.auth}</prop>
<!-- 超时时间 -->
<prop key="mail.smtp.timeout">${mail.smtp.timeout}</prop>
</props>
</property>
</bean>
<!-- 邮箱账户配置 -->
<bean id="simpleMailMessage" class="org.springframework.mail.SimpleMailMessage">
<!-- 发件人账户 -->
<property name="from" value="${mail.smtp.username}" />
</bean>
<!-- FreeMarker配置 -->
<bean id="freeMarker" class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer">
<property name="templateLoaderPath" value="resource/ftl/mail" /> <!-- 指定模板文件目录 -->
<property name="freemarkerSettings"> <!-- 设置FreeMarker环境属性 -->
<props>
<prop key="template_update_delay">60000</prop> <!-- 刷新模板的周期,单位为秒 -->
<prop key="default_encoding">GBK</prop> <!-- 模板的编码格式 -->
<prop key="locale">zh_CN</prop> <!-- 本地化设置 -->
</props>
</property>
</bean>
<!-- SpringMVC 文件上传配置 -->
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name="defaultEncoding" value="UTF-8"/>
<property name="maxUploadSize" value="200000"/> <!-- 文件大小(字节) -->
<property name="uploadTempDir" value="/resource/upload/temp"/> <!-- 临时目录 -->
</bean>
</beans>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:p="http://www.springframework.org/schema/p"
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/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd">
<!-- 启用spring mvc注解 -->
<context:annotation-config/>
<!-- 设置使用注解的类所在包 -->
<context:component-scan base-package="com.**.dao"/>
<context:component-scan base-package="com.**.service.impl"/>
<context:component-scan base-package="com.**.action"/>
<!-- 关闭URL地址扩展名支持 -->
<bean id="contentNegotiationManager" class="org.springframework.web.accept.ContentNegotiationManagerFactoryBean">
<property name="favorPathExtension" value="false" />
</bean>
<!-- 消息转换器 -->
<mvc:annotation-driven content-negotiation-manager="contentNegotiationManager">
<mvc:message-converters register-defaults="true">
<!-- String对象解析 -->
<bean class="org.springframework.http.converter.StringHttpMessageConverter">
<property name="supportedMediaTypes" value="text/html;charset=UTF-8"/>
</bean>
<!-- JSON对象解析 -->
<bean class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter">
<property name="supportedMediaTypes" value="application/json;charset=UTF-8"/>
</bean>
</mvc:message-converters>
</mvc:annotation-driven>
<!-- 对模型视图名称的解析,即在模型视图名称添加前后缀 -->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver" p:prefix="/" p:suffix=".jsp"/>
<!-- 加载自定义配置文件 -->
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:config/properties/dbtype.properties</value>
<value>classpath:config/properties/mail.properties</value>
</list>
</property>
</bean>
<!-- 配置关系型数据库连接池 (dbcp) -->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<!-- 数据源配置 -->
<property name="driverClassName" value="${driverClassName}"/>
<property name="url" value="${url}"/>
<property name="username" value="${username}"/>
<property name="password" value="${password}"/>
<property name="maxActive" value="200"/>
<property name="maxIdle" value="100"/>
<property name="minIdle" value="20"/>
<property name="maxWait" value="30000"/>
<!-- 防止连接超时 -->
<property name="validationQuery" value="SELECT 1" />
<property name="testOnBorrow" value="true"/>
</bean>
<!-- 配置Mybatis -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<!-- 自动扫描并加载某个目录下的多个SQL映射的XML文件,省掉Configuration.xml里的手工配置 -->
<property name="mapperLocations" value="classpath:config/mybatis/${dbType}/mapping/*.xml" />
<property name="dataSource" ref="dataSource" />
</bean>
<!-- 配置扫描器 -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<!-- 扫描某个目录下的包以及它的子包下的所有映射接口类 -->
<property name="basePackage" value="com.**.dao"/>
<!-- 如有多个数据源则此处需要指定:“sqlSessionFactoryBeanName” -->
<!--<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"/>-->
<!-- 配置该参数则只注册使用了annotationClass注解标记的DAO接口 -->
<!--<property name="annotationClass" value="org.springframework.stereotype.Repository"/> -->
</bean>
<!-- 配置Spring的事务管理器
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
</bean>
-->
<!-- 拦截器方式配置事物
<tx:advice id="transactionAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="add*" propagation="REQUIRED" />
<tx:method name="append*" propagation="REQUIRED" />
<tx:method name="insert*" propagation="REQUIRED" />
<tx:method name="save*" propagation="REQUIRED" />
<tx:method name="update*" propagation="REQUIRED" />
<tx:method name="modify*" propagation="REQUIRED" />
<tx:method name="edit*" propagation="REQUIRED" />
<tx:method name="delete*" propagation="REQUIRED" />
<tx:method name="remove*" propagation="REQUIRED" />
<tx:method name="repair" propagation="REQUIRED" />
<tx:method name="delAndRepair" propagation="REQUIRED" />
<tx:method name="get*" propagation="SUPPORTS" />
<tx:method name="find*" propagation="SUPPORTS" />
<tx:method name="load*" propagation="SUPPORTS" />
<tx:method name="search*" propagation="SUPPORTS" />
<tx:method name="datagrid*" propagation="SUPPORTS" />
<tx:method name="*" propagation="SUPPORTS" />
</tx:attributes>
</tx:advice>
<aop:config>
<aop:pointcut id="transactionPointcut" expression="execution(* com.kuangchi.service.impl..*.*(..))" />
<aop:advisor pointcut-ref="transactionPointcut" advice-ref="transactionAdvice" />
</aop:config>
-->
<!-- JavaMail服务 -->
<bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
<!-- 邮箱服务器配置 -->
<property name="host" value="${mail.smtp.host}" />
<property name="port" value="${mail.smtp.port}" />
<property name="username" value="${mail.smtp.username}" />
<property name="password" value="${mail.smtp.password}" />
<property name="javaMailProperties">
<props>
<!-- 发送模式 debug -->
<prop key="mail.debug">true</prop>
<!-- 开启SMTP服务器验证 -->
<prop key="mail.smtp.auth">${mail.smtp.auth}</prop>
<!-- 超时时间 -->
<prop key="mail.smtp.timeout">${mail.smtp.timeout}</prop>
</props>
</property>
</bean>
<!-- 邮箱账户配置 -->
<bean id="simpleMailMessage" class="org.springframework.mail.SimpleMailMessage">
<!-- 发件人账户 -->
<property name="from" value="${mail.smtp.username}" />
</bean>
<!-- FreeMarker配置 -->
<bean id="freeMarker" class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer">
<property name="templateLoaderPath" value="resource/ftl/mail" /> <!-- 指定模板文件目录 -->
<property name="freemarkerSettings"> <!-- 设置FreeMarker环境属性 -->
<props>
<prop key="template_update_delay">60000</prop> <!-- 刷新模板的周期,单位为秒 -->
<prop key="default_encoding">GBK</prop> <!-- 模板的编码格式 -->
<prop key="locale">zh_CN</prop> <!-- 本地化设置 -->
</props>
</property>
</bean>
<!-- SpringMVC 文件上传配置 -->
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name="defaultEncoding" value="UTF-8"/>
<property name="maxUploadSize" value="200000"/> <!-- 文件大小(字节) -->
<property name="uploadTempDir" value="/resource/upload/temp"/> <!-- 临时目录 -->
</bean>
</beans>