<?xml version="1.0" encoding="UTF-8"?>
xmlns="http://www.springframework.org/schema/beans"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.1.xsd ">
<!-- 数据源的配置 -->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<!-- 驱动注释 -->
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<!-- url -->
<property name="url" value="jdbc:mysql:///food" />
<!-- username -->
<property name="username" value="root" />
<!--password -->
<property name="password" value="root" />
</bean>
<!-- sessionFactory(session工厂)的配置 -->
<bean id="sessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<!-- 引用的数据源 -->
<property name="dataSource" ref="dataSource" />
<!-- 配置映射文件 -->
<property name="mappingResources">
<list>
<value>com/po/Userinfo.hbm.xml</value>
<value>com/po/Foodinfo.hbm.xml</value>
<value>com/po/Foodtype.hbm.xml</value>
<value>com/po/Orders.hbm.xml</value>
</list>
</property>
<!-- 配置hibernate的属性 -->
<property name="hibernateProperties">
<value>
hibernate.dialect=org.hibernate.dialect.MySQLInnoDBDialect
hibernate.show_sql=true
hibernate.format_sql=true
hibernate.hbm2ddl.auto=create
cache.provider_class=org.hibernate.cache.internal.NoCacheProvider
</value>
</property>
</bean>
<!-- 事务管理的配置 -->
<bean id="transactionManager"
class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<!-- 切面配置 -->
<aop:config>
<aop:pointcut id="productServiceMethods"
expression="execution(* com.food.service.*.*(..))" />
<aop:advisor advice-ref="txAdvice" pointcut-ref="productServiceMethods" />
</aop:config>
<!-- 事务传播属性的配置 -->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="delete*" propagation="REQUIRED" />
<tx:method name="update*" propagation="REQUIRED" />
<tx:method name="save*" propagation="REQUIRED" />
<tx:method name="*" read-only="true" />
</tx:attributes>
</tx:advice>