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:context="http://www.springframework.org/schema/context"
 4     xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
 5     xsi:schemaLocation="
 6         http://www.springframework.org/schema/beans 
 7         http://www.springframework.org/schema/beans/spring-beans.xsd
 8         http://www.springframework.org/schema/context 
 9         http://www.springframework.org/schema/context/spring-context.xsd
10         http://www.springframework.org/schema/tx 
11         http://www.springframework.org/schema/tx/spring-tx.xsd
12         http://www.springframework.org/schema/aop 
13         http://www.springframework.org/schema/aop/spring-aop.xsd">
14 
15     <!-- 配置数据源 dbcp数据源 -->
16     <bean >
17         <property name="driverClassName" value="${driverClass}" />
18         <property name="url" value="${jdbcUrl}" />
19         <property name="username" value="${user}" />
20         <property name="password" value="${password}"/>
21     </bean>
22 
23     <!-- 使用配置文件 加载 数据库需要的4要素 经常使用 -->
24     <context:property-placeholder location="classpath:jdbc.properties" />
25     
26     
27     <!--配置sessionFactory -->
28      <bean >
29         <!-- 读取hibernate配置文件<property name="configLocation" value="classpath:hibernate.cfg.xml"/> -->
30          <!-- 配置数据源 -->
31          <property name="dataSource" ref="dataSource"></property>
32          <!-- 配置映射文件  Teacher.hbm.xml -->
33          <property name="mappingDirectoryLocations" value="cn/bdqn/bean"/>
34          <property name="hibernateProperties">
35           <props>
36             <prop key="hibernate.hbm2ddl.auto">update</prop>
37             <prop key="hibernate.show_sql">true</prop>
38             <prop key="hibernate.format_sql">true</prop>
39             <prop key="hibernate.dialect">org.hibernate.dialect.MySQLInnoDBDialect</prop>
40           </props>
41          </property>
42      </bean>
43 
44   <!--配置dao层  -->
45   <bean  >
46   <property name="sessionFactory" ref="sessionFactory"/>
47 </bean>
48 
49  <!--配置service层  -->
50   <bean  >
51     <property name="dao" ref="teacherDao"></property>
52   </bean>
53 
54 <!-- 配置action层 -->
55 
56 <!-- ==========================事务======================================= -->
57 <!--  配置事务管理器  -->
58   <bean >
59     <property name="dataSource" ref="dataSource"/>
60   </bean>
61   
62   
63   <tx:advice > <!--  设置事务的通知  -->
64       <tx:attributes>
65       <!-- 对连接点上的方法进行事务属性的配置 -->
66        <tx:method name="add*"  isolation="DEFAULT" propagation="REQUIRED"/>
67        <tx:method name="delete*"  isolation="DEFAULT" propagation="REQUIRED"/>
68        <tx:method name="update*"  isolation="DEFAULT" propagation="REQUIRED"/>
69        <tx:method name="find*"  read-only="true" isolation="DEFAULT" propagation="REQUIRED"/>
70       </tx:attributes>
71   </tx:advice>
72   
73   <aop:config>
74       <!-- 指定切入点 -->
75      <aop:pointcut expression="execution(* *..service.*.*(..))" />
76      <aop:advisor advice-ref="txAdvice" pointcut-ref="myPoint"/>
77   </aop:config>
78 
79 </beans>
applicationContext.xml

相关文章: