springmvc框架搭建之xml配置說明(spring4+hibernate4)_第1頁
springmvc框架搭建之xml配置說明(spring4+hibernate4)_第2頁
springmvc框架搭建之xml配置說明(spring4+hibernate4)_第3頁
springmvc框架搭建之xml配置說明(spring4+hibernate4)_第4頁
全文預(yù)覽已結(jié)束

下載本文檔

版權(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ì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論