日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

spring整合hibernate的applicationContext.xml文件配置以及web.xml

發布時間:2025/3/15 编程问答 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 spring整合hibernate的applicationContext.xml文件配置以及web.xml 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

applicationContext.xml文件

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"?

? ? ? ?xmlns:tx="http://www.springframework.org/schema/tx"

? ? ? ?xmlns:aop="http://www.springframework.org/schema/aop"

? xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"?

? xsi:schemaLocation="http://www.springframework.org/schema/beans?

? http://www.springframework.org/schema/beans/spring-beans-3.1.xsd?

? http://www.springframework.org/schema/tx?

? http://www.springframework.org/schema/tx/spring-tx-3.1.xsd

? http://www.springframework.org/schema/aop?

? http://www.springframework.org/schema/aop/spring-aop-3.1.xsd">

? <!-- 配置hibernate連接信息 -->

? <bean id="source" class="org.apache.commons.dbcp.BasicDataSource">

? ? <property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"/>

? ? <property name="url" value="jdbc:oracle:thin:@localhost:1521:orcl"/>

? ? <property name="username" value="james"/>

? ? <property name="password" value="james"/>

? </bean>

? <!-- 配置sessionFactory -->

? <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">

? ? <property name="dataSource" ref="source"/>

? ? <!-- 配置hibernate其他參數 -->

? ? <property name="hibernateProperties">

? ? ? <props>

? ? ? ? <prop key="hibernate.show_sql">true</prop>

? ? ? ? <prop key="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</prop>

? ? ? ? <prop key="javax.persistence.validation.mode">none</prop>

? ? ? </props>

? ? </property>

? ? <!-- 配置hibernate映射文件,非注解情況下 -->

? ? <property name="mappingResources">

? ? ? <list>

? ? ? ? <value>entity/Comments.hbm.xml</value>

? ? ? ? <value>entity/News.hbm.xml</value>

? ? ? ? <value>entity/User.hbm.xml</value>

? ? ? ? <value>entity/Topic.hbm.xml</value>

? ? ? </list>

? ? </property>

? </bean>

? <!-- 配置dao注入sessionFactory -->

? <bean id="userDao" class="dao.UserDaoImpl">

? ? <property name="sessionFactory" ref="sessionFactory"/>

? </bean>

? <!-- 向userService注入dao -->

? <bean id="userService" class="service.UserServiceImpl">

? ? <property name="userDao" ref="userDao"></property>

? </bean>

? <!-- 定義事務管理器 ?-->

? <bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">

? ? <property name="sessionFactory" ref="sessionFactory"/>

? </bean>

? <!-- 配置事務增強 -->

? <tx:advice id="txAdvice" transaction-manager="txManager">

? ? <!-- 定義屬性,聲明事務規則 -->

? ? <tx:attributes>

? ? ? <tx:method name="find*" read-only="true"/>

? ? ? <tx:method name="search*" read-only="true"/>

? ? ? <tx:method name="query*" read-only="true"/>

? ? ? <tx:method name="add*" propagation="REQUIRED"/>

? ? ? <tx:method name="del*" propagation="REQUIRED"/>

? ? ? <tx:method name="update*" propagation="REQUIRED"/>

? ? ? <tx:method name="do*" propagation="REQUIRED"/>

? ? ? <tx:method name="*" propagation="REQUIRED" read-only="true"/>

? ? </tx:attributes>

? </tx:advice>

? <aop:config>

? ? <!-- 配置切入點 -->

? ? <aop:pointcut expression="execution(* service.*.*(..))" id="serviceMethod"/>

? ? <!-- 將事物增前和切入點結合 -->

? ? <aop:advisor advice-ref="txAdvice" pointcut-ref="serviceMethod"/>

? </aop:config>

</beans>

web.xml文件

<?xml version="1.0" encoding="UTF-8"?>

<web-app version="3.0"?

xmlns="http://java.sun.com/xml/ns/javaee"?

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"?

xsi:schemaLocation="http://java.sun.com/xml/ns/javaee?

http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">

? <display-name></display-name>

? <welcome-file-list>

? ? <welcome-file>index.jsp</welcome-file>

? </welcome-file-list>

? <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>

? <!-- OpenSessionInViewFilter,配置次功能可以延時加載,即保持會話隨事件開啟 -->

? <filter>

? ? <filter-name>OpenSessionInViewFilter</filter-name>

? ? <filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>

? </filter>

? <filter-mapping>

? ? <filter-name>OpenSessionInViewFilter</filter-name>

? ? <url-pattern>*.action</url-pattern>

? </filter-mapping>

</web-app>



轉載于:https://blog.51cto.com/12849946/1919279

總結

以上是生活随笔為你收集整理的spring整合hibernate的applicationContext.xml文件配置以及web.xml的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。