maven執行ssh三大框架+oracle資料庫的一般步驟及注意事項
maven執行ssh框架一般步驟:
(一)建立父工程(maven project)ssh_parent(pom)
1、配置pom.xml。
2、maven的倉庫有三種:本地倉庫、私服、中央倉庫,程式執行首先到本地,沒有去私服,再沒有去中央倉庫。
3、建立maven之前要配置好本地倉庫(settings.xml)。
(二)建立子工程(maven module)ssh_utils(jar,放入工具類,如:分頁,md5加密外掛等)
(三)建立子工程ssh_exception(jar,放入自定義異常類)
(三)建立子工程ssh_domain(jar)
1、在main/java下建立類Dept.java。
2、在main/resource下建立Dept.hbm.xml(和類Dept.java在同一級目錄下,否則報錯)。
(四)建立子工程ssh_dao(jar)
1、在pom.xml中新增ssh_utils.jar、ssh_domain.jar.
2、在main/java下建立BaseDao.介面和其實現類(通用dao增刪改查)。
3、在main/resource根目錄下建立applicationContext-dao.xml(hibernate.cfg.xml放入ssh_web中,便於管理配置檔案)。
(五)建立子工程ssh_service(jar)
1、在pom.xml中新增ssh_utils.jar、ssh_domain.jar、ssh_dao.jar。
2、在main/java下建立service介面和其實現類。
3、在main/resource根目錄下建立applicationContext-service.xml。
(六)建立子工程ssh_web(war)
*注意:建立完成後報錯,需要在webapp下面新增WEB-INF/web.xml.
1、在pom.xml中新增ssh_utils.jar、ssh_domain.jar、ssh_dao.jar、ssh_service.jar。
2、在main/java下建立Action類。
3、在main/resource根目錄下建立applicationContext-action.xml、applicationContext-.xml、
(1)無論是oracle10g還是oracle11g,hibernate方言配置都是org.hibernate.dialect.Oracle10gDialect
(2)hibernate.cfg.xml配置
<session-factory>
<property name="dialect">
org.hibernate.dialect.Oracle10gDialect
</property>
<property name="show_sql">true</property>
<property name="format_sql">false</property>
<property name="hbm2ddl.auto">none</property>
<!-- 懶載入,配合web.xml中配置的 openSessionInViewFilter -->
<property name="hibernate.enable_lazy_load_no_trans">true</property>
<!--校驗模式 JPA java persistent api-->
<property name="javax.persistence.validation.mode">none</property>
<!-- 載入對映檔案-->
<mapping resource="********/Dept.hbm.xml"></mapping>
</session-factory>
4、配置web.xml(spring監聽器和struts過濾器)。
(七)執行
1、先選中父工程右鍵run as-->maven install。
2、選中ssh_web右鍵run as-->maven build-->輸入tomcat:run(或者部署到tomcat中,同普通ssh專案)。