day35_Spring學習回顧_03
1.1、事務管理
基於xml配置的
1.配置事務管理器
jdbc:DataSourceTransactionManager
hibernate:HibernateTransactionManager
2.事務通知(詳情、屬性)
3. AOP編程,ABCD --> ABC
基於註解的
xml 配置
1.配置事務管理器
2.將配置事務管理器交予spring管理
3.目標類上通過註解配置事務詳情
@Transactional(propagation=Propagation.REQUIRED, isolation=Isolation.DEFAULT)
1.2、整合Junit
在測試類上
// 讓Junit去通知spring加載配置文件
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations="classpath:applicationContext.xml")
// 讓spring容器自動進行注入
@Autowired
@Test
1.3、整合web
web.xml 中的配置
1.確定xml位置
contextConfigLocation
classpath:applicationContext.xml
2.配置spring 監聽器,用於加載xml配置文件
org.springframework.web.context.ContextLoaderListener
1.4、整合ssh
1.hibernate po(domain/bean)
2.dao 層:
法一:需要HibernateTemplate,相當於session操作PO類 --> 必須提供setter方法,讓spring進行注入 --> 所以xml中必須要配置模板
save() update() delete() saveOrUpdate() find()
法二:繼承HibernateDaoSupport,需要注入SessionFactory,底層自動創建模板
dao方法中使用 this.getHibernateTemplate()
3.service 層:spring配置
org.hibernate.dialect.MySQL5Dialect
true
true
update
thread
4.web 層:aciton
使用的是:由struts去創建action
struts.xml 中的 注意:我們看到的好像是struts去創建action,其實底層使用的是spring去創建action
在Action類中,必須提供service名稱與spring配置文件一致。(如果【名稱】一致,將自動注入)
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.