<?xml version="1.0" encoding="UTF-8"?> <beans 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:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context" 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.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-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/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd"> <context:component-scan base-package="com.zzzy.test" /> <aop:aspectj-autoproxy proxy-target-class="true"/> <!-- 数据源配置 --> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"> <property name="driverClassName" value="oracle.jdbc.OracleDriver"> </property> <property name="url" value="jdbc:oracle:thin:localhost:1521:orcl"> </property> <property name="username" value="scott"></property> <property name="password" value="tiger"></property> </bean> <!-- factory 的配置 --> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"> <property name="dataSource"> <ref bean="dataSource" /> </property> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect"> org.hibernate.dialect.Oracle9Dialect </prop> <prop key="hibernate.show_sql">true</prop> <prop key="hibernate.format_sql">true</prop> <prop key="hibernate.hbm2ddl.auto">update</prop> <!-- 用于生成有助于调试的注释信息,默认为关闭 --> <prop key="hibernate.use_sql_comments">false</prop> </props> </property> <!-- 扫描使用注解的实体类所在的包,不再使用annotatedClasses参数 --> <property name="packagesToScan"> <list> <value>com.zzzy.test</value> </list> </property> </bean> <bean id="transcationManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactory"/> </bean> <tx:advice id="txAdvice" transaction-manager="transcationManager"> <tx:attributes> <tx:method name="query*" propagation="REQUIRED" read-only="true"/> <tx:method name="add*" propagation="REQUIRED"/> <tx:method name="*" read-only="true" /> </tx:attributes> </tx:advice> <aop:config > <aop:pointcut id="txMethod" expression="execution(* com.zzzy.test.ServiceDaoImp..*.*(..)) "/> <aop:advisor advice-ref="txAdvice" pointcut-ref="txMethod" /> </aop:config> <bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate"> <property name="sessionFactory" ref="sessionFactory"/> </bean> </beans>
时间: 2024-10-12 09:06:28