使用Java企业级技术开发大型系统(3)
沒有(2)
?
web.xml:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
applicationContext.xml:
<!-- 全局采用注解配置 -->
<context:annotation-config></context:annotation-config>
<!-- 注解掃描范圍 -->
<context:component-scan base-package="com.xx"></context:component-scan>
<!-- 配置事務通知 -->
<bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"> </property>
</bean>
<!-- 聲明式事物采取注解植入 -->
<tx:annotation-driven transaction-manager="txManager"/>
struts.xml:
<struts>
<package name="default" namespace="/" extends="struts-default">
<action name="findAll" class="customerAction" method="findAll">
<result name="success">index.jsp</result>
</action>
<action name="findPage" class="customerAction" method="findByPage">
<result name="success">page.jsp</result>
</action>
</package>
</struts>
創建事務通知 通知以XXX方法打頭 需要怎樣的事務處理
以save開頭的方法 需要事務處理
以find開頭的方法 只讀即可 (不需要事務)
Spring框架支持 通過MyEclipse導入
需要加入5個jar包
Hibernate框架支持 通過MyEclipse導入
注意:刪除cglib-2.2.jar
Struts2框架支持 手動引入Struts2jar包
提示:
從struts-2.1.8.1-all.zip壓縮包中找apps目錄下的
struts2-blank-2.1.8.1.war文件直接打開,從這個項
目中可以找到相關的jar包,包括struts.xml和web.xml都
可以從這個項目中找到。
注意: 多加入一個 struts2-spring-plugin-2.1.8.1.jar
調整各個配置文件
applicationContext.xml 修改警告
struts.xml 修改警告
web.xml 配置監聽(Listener)
org.springframework.web-3.0.1.RELEASE-A.jar 包中找 : org.springframework.web.context.ContextLoaderListener
使用Hibernate反向生成實體映射
檢查自動生成的映射文件和實體類
編寫DAO 在spring中注冊
注意:不在使用HibernateUtil,而采用繼承HibernateDaoSupport的方式
編寫BIZ 在spring中注冊
編寫Action 在spring中注冊
注意:
scope="prototype"
struts.xml 配置文件中 class不是配置類路徑了,而是配置spring中的bean id
Hibernate加載策略
延遲加載 session.load() 代理對象,當使用這個對象的屬性時才去加載
load查詢的對象不存在時拋出異常
立即加載 session.get() 立即發送SQL語句到數據庫并填充對象
get查詢的對象不存在時候返回null
使用內部類這種寫法比較靠譜,但是需要注意如果使用外部類成員,需要使用final修飾
轉載于:https://www.cnblogs.com/a2367763409/p/6649380.html
總結
以上是生活随笔為你收集整理的使用Java企业级技术开发大型系统(3)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 使用Dom4j操作XML数据
- 下一篇: 有出山的完整版吗