1条回答 默认 最新
- 菜鸟程序元 2015-05-21 02:39关注
<?xml version="1.0" encoding="UTF-8"?>
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.1.xsd"><!-- 配置数据源 --> <bean id="basicDataSource" class="org.apache.commons.dbcp.BasicDataSource"> <property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" /> <property name="url" value="jdbc:oracle:thin:@localhost:1521:orcl" /> <property name="username" value="scott" /> <property name="password" value="tiger" /> </bean> <!-- 配置会话工厂 --> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <!-- 引用的数据源 --> <property name="dataSource" ref="basicDataSource" /> <!-- 对于hibernate框架要做的配置 --> <property name="hibernateProperties"> <props> <!-- 方言 --> <prop key="hibernate.dlalect">org.hibernate.dialect.Oracle10gDialect</prop> <!-- 是否显示SQL语句 --> <prop key="hibernate.show_sql">false</prop> <!-- 是否格式化SQL --> <prop key="hibernate.format_sql">false</prop> </props> </property> <!-- 指定映射文件的路径 --> <property name="mappingDirectoryLocations"> <list> <value>classpath:com/bdqn/entity/</value> </list> </property> </bean> <!-- Dao --> <bean id="customerDao" class="com.bdqn.dao.impl.CustomerDaoImpl"> <property name="sessionFactory" ref="sessionFactory"></property> </bean> <bean id="deptDao" class="com.bdqn.dao.impl.DeptDaoImpl"> <property name="sessionFactory" ref="sessionFactory"></property> </bean> <!-- Service --> <bean id="deptService" class="com.bdqn.service.impl.DeptServiceImpl"> <property name="deptDao" ref="deptDao"></property> </bean> <bean id="customerService" class="com.bdqn.service.impl.CustomerServiceImpl"> <property name="customerDao" ref="customerDao"></property> </bean> <!-- Action --> <bean id="customerAction" class="com.bdqn.action.CustomerAction" scope="prototype"> <property name="customerService" ref="customerService"></property> <property name="deptService" ref="deptService"></property> </bean> <!-- 配置事务 --> <bean id="tx" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactory" /> </bean> <!-- 定义传播特性 --> <tx:advice id="txAdvice" transaction-manager="tx"> <tx:attributes> <tx:method name="find*" read-only="true" /> <tx:method name="search*" read-only="true" /> <tx:method name="query*" read-only="true" /> <tx:method name="get*" read-only="true" /> <tx:method name="add*" propagation="REQUIRED" /> <tx:method name="save*" propagation="REQUIRED" /> <tx:method name="insert*" propagation="REQUIRED" /> <tx:method name="del*" propagation="REQUIRED" /> <tx:method name="remove*" propagation="REQUIRED" /> <tx:method name="update*" propagation="REQUIRED" /> <tx:method name="modify*" propagation="REQUIRED" /> <tx:method name="*" propagation="REQUIRED" /> </tx:attributes> </tx:advice> <aop:config> <aop:pointcut expression="execution(public * com.bdqn.service.impl.*.*(..))" id="pc" /> <aop:advisor advice-ref="txAdvice" pointcut-ref="pc" /> </aop:config>
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报