<?xml version="1.0" encoding="UTF-8"?>
<beans
default-autowire="byName"
default-lazy-init="true"
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-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/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
">
<!-- 開啓註解配置 -->
<context:annotation-config />
<!-- 對指定的包進行組件掃描 -->
<context:component-scan base-package="com.lun" />
<!--鏈接數據庫 -->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"></property>
<property name="url" value="jdbc:oracle:thin:@127.0.0.1:1521:orcl"></property>
<property name="username" value="lun"></property>
<property name="password" value="123"></property>
</bean>
<!-- 配置hibernate的sessionFactory -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource"></property>
<property name="hibernateProperties">
<props>
<!-- 數據庫方言 -->
<prop key="hibernate.dialect">org.hibernate.dialect.Oracle9Dialect</prop>
<!-- 在控制檯打印執行的sql語句 -->
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
<!-- 加載所有的實體配置文件 -->
<property name="mappingDirectoryLocations">
<list>
<value>classpath:com/lun/entity</value>
</list>
</property>
</bean>
<!-- 事務處理器 -->
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<!-- 事務通知配置 -->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="get*" read-only="true" propagation="NOT_SUPPORTED" />
<tx:method name="find*" read-only="true" propagation="NOT_SUPPORTED" />
<tx:method name="select*" read-only="true" propagation="NOT_SUPPORTED" />
<tx:method name="save*" rollback-for="Exception" propagation="REQUIRED" />
<tx:method name="add*" rollback-for="Exception" propagation="REQUIRED" />
<tx:method name="update*" rollback-for="Exception" propagation="REQUIRED" />
<tx:method name="del*" rollback-for="Exception" propagation="REQUIRED" />
<tx:method name="*" rollback-for="Exception" propagation="REQUIRED" />
</tx:attributes>
</tx:advice>
<!-- 事務切面配置 -->
<aop:config>
<aop:pointcut expression="execution(* com.lun.biz.*.*(..))" id="transactionPointcut" />
<aop:advisor advice-ref="txAdvice" pointcut-ref="transactionPointcut" />
</aop:config>
<!-- 注入jdbcTemplate -->
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<constructor-arg ref="dataSource"/>
</bean>
<!-- 注入hibernateTemplate -->
<bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
</beans>