加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-16 06:38:50 所属栏目:百科 来源:网络整理
导读:?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/XMLS

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读