1 <?xml version="1.0" encoding="UTF-8"?> 2 <beans xmlns="http://www.springframework.org/schema/beans" 3 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc" 4 xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p" 5 xmlns:tx="http://www.springframework.org/schema/tx" 6 xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd"> 7 8 <!-- mvc注解驱动,默认支持json转换 --> 9 <mvc:annotation-driven/> 10 <context:annotation-config></context:annotation-config> 11 12 <!-- 注解扫描的包路径 --> 13 <context:component-scan base-package="wms.controller"/> 14 15 <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close" 16 p:driverClass="com.mysql.jdbc.Driver" 17 p:jdbcUrl="jdbc:mysql://localhost:3306/test?useSSL=true" 18 p:user="root" p:password="1234" 19 p:maxPoolSize="40" p:minPoolSize="2" p:initialPoolSize="2" p:maxIdleTime="30" p:loginTimeout="10" 20 /> 21 22 <bean id="sessionFactory" class="org.springframework.orm.hibernate5.LocalSessionFactoryBean" p:dataSource-ref="dataSource"> 23 <property name="hibernateProperties"> 24 <props> 25 <prop key="hibernate.dialect">org.hibernate.dialect.MySQL5InnoDBDialect</prop> 26 <prop key="hibernate.hbm2ddl.auto">update</prop> 27 <prop key="hibernate.show_sql">true</prop> 28 <prop key="hibernate.format_sql">true</prop> 29 <prop key="org.hibernate.cache">true</prop> 30 <prop key="current_session_context_class">thread</prop> 31 </props> 32 </property> 33 <property name="packagesToScan"> 34 <list> 35 <value>wms.model</value> 36 </list> 37 </property> 38 </bean> 39 40 <!-- 设定transactionManager --> 41 <bean id="txManager" 42 class="org.springframework.orm.hibernate5.HibernateTransactionManager"> 43 <property name="sessionFactory" ref="sessionFactory"/> 44 </bean> 45 46 <!--启动spring事务注解功能 --> 47 <tx:annotation-driven transaction-manager="txManager"/> 48 </beans>