<?xml version="1.0" encoding="UTF-8"?>
<beans
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-2.5.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
<!-- 配置数据源 -->
<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:@localhost:1521:orcl"></property>
<!-- @localhost代表主机地址,也可以其他电脑的ip -->
<property name="username" value="hruser"></property>
<property name="password" value="hruser"></property>
</bean>
<!-- 配置SessionFactory Bean-->
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionfactorybean">
<!-- 为我们的SessionFactory注入配制好的数据源 -->
<property name="dataSource" ref="dataSource"></property>
<!-- 添加Hibernate配置参数,如数据库方言,showsql、formatsql等等 -->
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.Oracle10gDialect
</prop>
<!-- 表示允许自动提交 -->
<prop key="hibernate.connection.autocommit">true</prop>
<!-- 控制台显示sql语句 -->
<prop key="hibernate.show_sql">true</prop>
<!-- 格式化sql语句 -->
<prop key="hibernate.format_sql">true</prop>
</props>
</property>
<!-- 添加映射文件 -->
<property name="mappingResources">
<list>
<value>com/jbit/hr/entity/HrDeptone.hbm.xml</value>
<value>com/jbit/hr/entity/HrDepttwo.hbm.xml</value>
<value>com/jbit/hr/entity/HrDeptthree.hbm.xml</value>
<value>com/jbit/hr/entity/HrHumanDoc.hbm.xml</value>
<value>com/jbit/hr/entity/HrMajor.hbm.xml</value>
<value>com/jbit/hr/entity/HrMajorKind.hbm.xml</value>
<value>com/jbit/hr/entity/HrPbAttri.hbm.xml</value>
<value>com/jbit/hr/entity/HrPostIssue.hbm.xml</value>
<value>com/jbit/hr/entity/HrResume.hbm.xml</value>
<value>com/jbit/hr/entity/HrSalary.hbm.xml</value>
<value>com/jbit/hr/entity/HrSub.hbm.xml</value>
<value>com/jbit/hr/entity/HrSubone.hbm.xml</value>
<value>com/jbit/hr/entity/HrSubStandard.hbm.xml</value>
<value>com/jbit/hr/entity/HrSubtwo.hbm.xml</value>
<value>com/jbit/hr/entity/HrUser.hbm.xml</value>
<!-- 有多少个映射文件写多少个value -->
</list>
</property>
<!-- 另外一种映射文件配置方式
下面的这一种方式不能在main方法中进行测试,要测试需用上面的这种方法
--> <!-- <property name="mappingDirectoryLocations"> <list> <value>WEB-INF/classes/com/jbit/hr/entity/</value> 如果映射文件分布在不同的路径还可以继续添加value标签 </list> </property> --> </bean> <!-- 配置声明式事务处理 --> <!-- 1.配置事务管理器 --> <bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactory"></property> </bean> <!-- 2.配置事务增强,指定事务事务传播机制 --> <tx:advice id="txAdvice" transaction-manager="txManager"> <tx:attributes> <tx:method name="get*" read-only="true"/> <tx:method name="find*" read-only="true"/> <tx:method name="search*" read-only="true"/> <tx:method name="query*" read-only="true"/> <tx:method name="add*" propagation="required"/> <tx:method name="submit*" 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="check*" propagation="required"/> <tx:method name="do*" propagation="required"/> <tx:method name="merge*" propagation="required"/> <tx:method name="*" propagation="required" read-only="true"/> </tx:attributes> </tx:advice> <!-- 3.配置切入点 --> <aop:config> <!-- 定义切入点 --> <aop:pointcut expression="execution(* com.jbit.hr.service.*.*(..))" id="pointcut"/> <!-- 将我们的切入点织入增强处理 --> <aop:advisor advice-ref="txAdvice" pointcut-ref="pointcut"/> </aop:config> <import resource="com.jbit.hr.service.xml"/> <import resource="com.jbit.hr.dao1.xml" /> </beans>
原文链接:https://www.f2er.com/xml/297789.html