SSH框架整合时applicationContext.xml的配置,关于在main方法中测试注意的事项

<?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>

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值