1.下面是spring-mvc的配置文件:web
<?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:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd">;spring
<!-- 登陸鑑權攔截器 --> <mvc:interceptors> <mvc:interceptor> <mvc:mapping path="/**" /> <mvc:exclude-mapping path="/index"/> <bean class="com.flower.mall.commons.interceptors.AuthHandlerInterceptor" /> </mvc:interceptor> </mvc:interceptors> <!-- 支持springMVC返回JSON格式 --> <mvc:annotation-driven> <mvc:message-converters> <bean id="fastJson" class="com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter"> <property name="supportedMediaTypes"> <list> <value>application/json;charset=UTF-8</value> </list> </property> </bean> </mvc:message-converters> </mvc:annotation-driven> <!-- 自動掃描 @Controller--> <context:component-scan base-package="com.flower.mall.controller"/> <!--定義跳轉的文件的先後綴 ,視圖模式配置--> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix" value="/WEB-INF/view/"/> <property name="suffix" value=".jsp"/> </bean> <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"> <property name="maxUploadSize" value="35000000" /> <property name="defaultEncoding" value="UTF-8" /> </bean>
</beans>sql
2.下面是spring-mybatis的配置文件:apache
<?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"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.2.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-4.2.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-4.2.xsd">;json
<!-- 自動掃描 --> <context:component-scan base-package="com.flower.mall"/> <!-- 第一種方式:加載一個properties文件 --> <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="location" value="classpath:jdbc.properties"/> </bean> <!-- 第二種方式:加載多個properties文件 <bean id="configProperties" class="org.springframework.beans.factory.config.PropertiesFactoryBean"> <property name="locations"> <list> <value>classpath:jdbc.properties</value> <value>classpath:common.properties</value> </list> </property> <property name="fileEncoding" value="UTF-8"/> </bean> <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PreferencesPlaceholderConfigurer"> <property name="properties" ref="configProperties"/> </bean> --> <!-- 配置數據源 --> <bean id="dataSource" class="org.apache.commons.dbcp2.BasicDataSource" destroy-method="close"> <property name="driverClassName" value="${driverClass}"/> <property name="url" value="${jdbcUrl}"/> <property name="username" value="${username}"/> <property name="password" value="${password}"/> <!-- 初始化鏈接大小 --> <property name="initialSize" value="${initialSize}"/> <!-- 鏈接池最大數量 --> <property name="maxTotal" value="${maxActive}"/> <!-- 鏈接池最大空閒 --> <property name="maxIdle" value="${maxIdle}"/> <!-- 鏈接池最小空閒 --> <property name="minIdle" value="${minIdle}"/> <!-- 獲取鏈接最大等待時間 --> <property name="maxWaitMillis" value="${maxWait}"/> </bean> <!-- mybatis和spring完美整合,不須要mybatis的配置映射文件 --> <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <property name="dataSource" ref="dataSource"/> <!-- 自動掃描mapping.xml文件 --> <property name="mapperLocations" value="classpath:mapper/*/*.xml"/> </bean> <!-- DAO接口所在包名,Spring會自動查找其下的類 --> <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"> <property name="basePackage" value="com.flower.mall.dao"/> <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"/> </bean> <!-- (事務管理)transactionManager, use JtaTransactionManager for global tx --> <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="dataSource"/> </bean> <!-- 配置AOP通知 --> <tx:advice id="txAdvice"> <!-- 配置事務屬性 --> <tx:attributes> <!-- 添加事務管理的方法 --> <tx:method name="save*"/> <tx:method name="add*"/> <tx:method name="insert*"/> <tx:method name="delete*"/> <tx:method name="update*"/> <tx:method name="edit*"/> <tx:method name="select*" read-only="true"/> <tx:method name="query*" read-only="true"/> <tx:method name="get*" read-only="true"/> <tx:method name="list*" read-only="true"/> </tx:attributes> </tx:advice> <!-- 配置AOP,爲添加事務管理的操做配置AOP --> <aop:config> <!-- 引入的Spring定義的事務通知,須要使用aop:advisor --> <aop:advisor advice-ref="txAdvice" pointcut="execution(* com.flower.mall.service.*.*(..))" /> </aop:config>
</beans>spring-mvc