SSH-基礎篇-hibernate.cfg.xml

app<?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:aop="http://www.springframework.org/schema/aop"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-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">




<!-- $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ -->


<!-- 配置session工廠 -->

<!--方式1:直接讀取hibernate.cfg.xml  -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="configLocation">
<value>classpath:hibernate.cfg.xml</value>
</property>
</bean>



<!-- $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ -->

<!--添加聲明式事務 -->

<!--定義一個事務管理器 -->
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>

<!--定義事務規則 -->
<aop:config>
<aop:pointcut id="mypoint" expression="execution(* cn.jbit.ssh.service..*.*(..))"/>
<aop:advisor advice-ref="txAdvice" pointcut-ref="mypoint"/>
</aop:config>

<!-- 事務增強 -->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="find*" read-only="true"/>
<tx:method name="add*"  propagation="REQUIRED"/>
<tx:method name="save*" propagation="REQUIRED"/>
<tx:method name="update*"  propagation="REQUIRED"/>
<tx:method name="del*"  propagation="REQUIRED"/>
<tx:method name="*" propagation="REQUIRED"/>
</tx:attributes>
</tx:advice>



<!-- $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ -->



<!-- Dept設置 -->

<!--dao 配置 -->
<!-- scope是作用域,默認的是singelton(單例模式),建議用prototype(每次請求時都創建一個新的bean)
request(每次請求創建一個新的實例,需要在webxml下配置監聽),session和globalsession() -->

<bean id="deptDao" class="cn.jbit.ssh.dao.impl.DeptDaoImpl" scope="prototype">
  <property name="sessionFactory" ref="sessionFactory" ></property>
</bean>

<!--service配置  -->
<bean id="deptService" class="cn.jbit.ssh.service.impl.DeptServiceImpl">
<property name="dao" ref="deptDao"></property>
</bean> 

<!-- acion配置 -->
<bean id="deptAction" class="cn.jbit.ssh.action.DeptAction">
  <property name="deptService" ref="deptService"></property>
</bean>



</beans>


 
<!-- ///////////////////////////////////////////////////////////////////////////////////// -->
<!-- 單詞 -->
<!-- propagation[,prɒpə'ɡeɪʃən]傳播;繁殖;增殖 -->
<!-- transaction[træn'zækʃ(ə)n; trɑːn-; -'sæk-]n. 交易;事務;辦理;會報,學報 -->
<!-- scope[skəʊp]範圍;餘地;視野;眼界;導彈射程 -->
<!-- prototype['prəʊtətaɪp]原型;標準,模範 -->
發佈了38 篇原創文章 · 獲贊 2 · 訪問量 1萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章