



下載本文檔
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
SpringMVC框架搭建說明Spring4.1.4+hibernate4.3.81、web.xml配置程序運(yùn)行時(shí)從web.xml開始,加載順序?yàn)椋篶ontext-param->listener->filter->structs(如果使用structs的話)->servlet如下為web.xml的配置說明<?xmlversion="1.0"encoding="UTF-8"?><web-appxmlns:xsi="/2001/XMLSchema-instance"xmlns="/xml/ns/javaee"xmlns:web="/xml/ns/javaee/web-app_2_5.xsd"xsi:schemaLocation="/xml/ns/javaee/xml/ns/javaee/web-app_2_5.xsd"id="WebApp_ID"version="2.5"><!—-顯示項(xiàng)目名稱--><display-name>bmymis2</display-name>指定配置文件位置,contextConfigLocationContextLoaderListenerContextLoaderListenerapplicationContext-*.xml,ApplicationContext<context-param><param-name>contextConfigLocation</param-name><param-value>classpath:applicationContext-*.xml</param-value></context-param><!--定義SPRING監(jiān)聽器,啟動(dòng)Web容器時(shí),自動(dòng)裝配ApplicationContext的配置信息--><listener><listener-class>org.springframework.web.context.ContextLoaderListener</listener-class></listener><!—-字符編碼過濾器,解決中文亂碼問題--><filter><filter-name>encodingFilter</filter-name><filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class><init-param><param-name>encoding</param-name><param-value>UTF-8</param-value></init-param><init-param><param-name>forceEncoding</param-name><param-value>true</param-value></init-param></filter>springmvc配置--><servlet><servlet-name>springServlet</servlet-name><servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class><init-param><param-name>contextConfigLocation</param-name><param-value>classpath*:/spring-mvc.xml</param-value></init-param><load-on-startup>1</load-on-startup>//容器啟動(dòng)時(shí)首先初始化該servlet</servlet><servlet-mapping><servlet-name>springServlet</servlet-name><url-pattern>/</url-pattern>//springmvc處理</servlet-mapping><!—-瀏覽器輸入到項(xiàng)目名,默認(rèn)打開如下配置頁面--><welcome-file-list><welcome-file>/web/login.jsp</welcome-file></welcome-file-list><!—-錯(cuò)誤跳轉(zhuǎn)頁面--><error><error-code>404</error-code><location>/404.html</location></error></web-app>2、applicationContext-common.xml配置:<beansxmlns<beansxmlns="/schema/beans"xmlns:context="/schema/context"xmlns:xsi="/2001/XMLSchema-instance"xmlns:tx="/schema/tx"xmlns:aop="/schema/aop"xsi:schemaLocation="/schema/beans/schema/context/schema/context/spring-context-4.0.xsd/schema/aop/schema/aop/spring-aop-4.0.xsd/schema/tx/schema/tx/spring-tx-4.0.xsd">Spring配置文件的最前面加載,即第一個(gè)加載--><context:property-placeholderlocation="classpath:perties"/>n,并保證d的屬性被注入,有了該配置,那么<context:annotation-config/>這個(gè)配置就可以省略(以下配置包含了<context:annotation-config/>配置)--><context:component-scanbase-package="xxx.xxx.xxx"/>數(shù)據(jù)源配置,DBCP數(shù)據(jù)庫(kù)連接池--><beanid="dataSourceclass="mons.dbcp.BasicDataSource"destroy-method="close">beandestroy-method="close"的作用是當(dāng)數(shù)據(jù)庫(kù)連接不使用的時(shí)候,就把該連接重新放到數(shù)據(jù)池中,方便下次使用調(diào)用--><<propertyname="driverClassName"value="${jdbc.driverClassName}"/><propertyname="url"value="${jdbc.url}"/><propertyname="username"value="${jdbc.username}"/><propertyname="password"value="${jdbc.password}"/>
e的注解配置<<beanid="sessionFactory"class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"><propertyname="dataSource"ref="dataSource"/><propertyname="hibernateProperties"><props><propkey="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop><propkey="hibernate.dialect">${hibernate.dialect}</prop><propkey="hibernate.show_sql">${hibernate.show_sql}</prop></props></property><propertyname="packagesToScan"value="xxx.xxx.xxx.model"/></bean>Hibernate事務(wù)管理器--><beanid="transactionManager"class="org.springframework.orm.hibernate4.HibernateTransactionManager"><propertyname="sessionFactory"ref="sessionFactory"/></bean><!--配置事務(wù)異常封裝--><beanid="persistenceExceptionTranslationPostProcessor"class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor"/><!--聲明式容器事務(wù)管理,transaction-managertransactionManager<tx:adviceid="txAdvice"transaction-manager="transactionManager"><tx:attributes><tx:methodname="add*"propagation="REQUIRED"/><tx:methodname="get*"propagation="REQUIRED"/><tx:methodname="*"read-only="true"/></tx:attributes></tx:advice><aop:configexpose-proxy="true"><!--只對(duì)業(yè)務(wù)邏輯層實(shí)施事務(wù)--><aop:pointcutid="txPointcut"expression="execution(*xxx.xxx.xxx.service..*.*(..))"/>AdvisortxPointcut、txAdvice<aop:advisorpointcut-ref="txPointcut"advice-ref="txAdvice"/></aop:config></beans>3、perties配置jdbc.driverClassName=org.postgresql.Driverjdbc.url=jdbc:postgresql://ip:5432/數(shù)據(jù)庫(kù)名jdbc.username=postgresjdbc.password=123hibernate.dialect=org.hibernate.dialect.PostgreSQLDialecthibernate.show_sql=truehibernate.format_sql=false4、spring-mvc.xml配置<beansxmlns="/schema/beans"xmlns:context="/schema/context"<beansxmlns="/schema/beans"xmlns:context="/schema/context"xmlns:mvc="/schema/mvc"xmlns:p="/schema/p"xmlns:xsi="/2001/XMLSchema-instance"xmlns:tx="/schema/tx"xsi:schemaLocation="/schema/beans/schema/beans/spring-beans-3.0.xsd/schema/context/schema/context/spring-context-3.0.xsd/schema/mvcHYPERLINK"/schema/mvc/
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- T-ZNZ 264.1-2024 重金屬中度污染農(nóng)田土壤修復(fù)和安全利用技術(shù)規(guī)范 第1部分:超積累東南景天與油葵輪作
- 二零二五年度車輛轉(zhuǎn)讓與二手車交易及金融服務(wù)協(xié)議
- 2025年度蛋糕店與體育賽事合作贊助協(xié)議
- 2025年度道路橋梁維修施工安全協(xié)議書
- 2025年度網(wǎng)絡(luò)安全產(chǎn)品銷售提成與技術(shù)服務(wù)合同
- 二零二五年度企業(yè)員工宿舍三方租賃協(xié)議
- 二零二五年度臨時(shí)廚房工作人員聘用合同
- 二零二五年度個(gè)體商戶勞動(dòng)合同(體育賽事組織與運(yùn)營(yíng))
- 中學(xué)生環(huán)保行動(dòng)策劃案解讀
- 監(jiān)控項(xiàng)目合作合同監(jiān)控施工合同
- 中國(guó)骨關(guān)節(jié)炎診療指南(2024版)解讀
- 【歷史】2025年春季七下歷史新教材課本答案大全(想一想、材料研讀、讀地圖、課后活動(dòng))
- 高端寫字樓物業(yè)管理思路
- 江蘇省中小學(xué)生金鑰匙科技競(jìng)賽(高中組)考試題及答案
- 2024-2030年中國(guó)ORC低溫余熱發(fā)電系統(tǒng)行業(yè)商業(yè)模式創(chuàng)新規(guī)劃分析報(bào)告
- 【MOOC】三維設(shè)計(jì)與表達(dá)-北京林業(yè)大學(xué) 中國(guó)大學(xué)慕課MOOC答案
- 婦幼健康信息平臺(tái)共享數(shù)據(jù)集應(yīng)用規(guī)范第1部分孕產(chǎn)婦保健
- 輸液港的輸液與維護(hù)
- 非洲豬瘟病毒基因IⅡ型重組毒株、基因I型弱毒株和基因Ⅱ型毒株鑒別三重?zé)晒釶CR檢測(cè)方法
- 2024解析:第十四章內(nèi)能的利用-講核心(解析版)
- 各類應(yīng)急風(fēng)險(xiǎn)預(yù)案的防范
評(píng)論
0/150
提交評(píng)論