Jpetstore(srping 版本)示例學(xué)習(xí)筆記[1]
Posted on 2006-12-28 12:40 itspy 閱讀(1131) 評(píng)論(0) 編輯 收藏 所屬分類: JAVA技術(shù)我學(xué)習(xí)的版本是spring-framework-1.2.8帶的版本,我主要學(xué)習(xí)的是如下幾點(diǎn):Spring的MVC,struts的MVC(可選),ibatis。
Action層有兩個(gè)實(shí)現(xiàn),一個(gè)通過Spring自帶的MVC來實(shí)現(xiàn),另外一個(gè)通過Struts來實(shí)現(xiàn).
兩者的切換是通過web.xml文件來實(shí)現(xiàn)的,在此文件中有如下代碼.
?<servlet-mapping>
??<servlet-name>petstore</servlet-name>
??<!--
??<servlet-name>action</servlet-name>
??-->
??<url-pattern>*.do</url-pattern>
?</servlet-mapping>
默認(rèn)的是使用Spring自帶的MVC來實(shí)現(xiàn),切換成Struts只要兩步
1)注釋<servlet-name>petstore</servlet-name>
2)把<servlet-name>action</servlet-name>的注釋去了.
要真正的部署運(yùn)行這個(gè)服務(wù),要啟動(dòng)數(shù)據(jù)庫(kù),使用默認(rèn)的方式是點(diǎn)擊db/hsqldb/server.bat
?
?
比如jpetstore里面的petstore-servlet.xml如何載入系統(tǒng),如何與系統(tǒng)關(guān)聯(lián)?
在WEB-INF下面DispatchServlet會(huì)默認(rèn)查找與自己相關(guān)的Web應(yīng)用上下文.?
?<servlet>
??<servlet-name>petstore</servlet-name>
??<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
??<load-on-startup>2</load-on-startup>
?</servlet>
比如上面的定義就會(huì)在WEB-INF下面查找petstore-servlet.xml文件,并載入了.至于是哪段代碼起作用,我是找了半天也沒找到.
Spring代碼功能太強(qiáng)大了,代碼也太多了不好找,不過最后好像是跟蹤到這個(gè)地方了HttpServletBean.init()函數(shù).
?