利用Spring整合Hibernate时的XML文件配置 applicationContext.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd"> <!-- 向 Spring 容器注册
AutowiredAnnotationBeanPostProcessor、CommonAnnotationBeanPostProcessor、PersistenceAnnotationBeanPostProcessor、RequiredAnnotationBeanPostProcessor 这 4 个BeanPostProcessor
识别注解 -->
<context:annotation-config /> <!-- 自动扫描base-pack子包下面Java文件,如果扫描到有@Component @Controller @Service等这些注解的类,则把这些类注册为bean -->
<context:component-scan base-package="cqvie.yjq" /> <!-- ************************************************************************************************ -->
<!-- 定义.properties文件 -->
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="locations" value="classpath:jdbc.properties"/> <!-- 如果有多个.properties文件,则可以透过 locations属性来设定:
<property name="locations">
<list>
<value>classpath:mailsender1.properties</value>
<value>classpath:mailsender2.properties</value>
</list>
</property>
-->
</bean> <!-- ************************************************************************************************ -->
<!-- 配置数据源 -->
<bean id="dataSource" destroy-method="close" class="org.apache.commons.dbcp2.BasicDataSource">
<property name="driverClassName" value="${jdbc.driverClassName}"/>
<property name="url" value="${jdbc.url}"/>
<property name="username" value="${jdbc.username}"/>
<property name="password" value="${jdbc.password}"/>
</bean> <!-- ************************************************************************************************ -->
<!-- 自动创建 SessionFactory -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<!-- 等价于下面的方法
<property name="annotatedClasses">
<list>
<value>cqvie.yjq.model.User</value>
<value>cqvie.yjq.model.Log</value>
</list>
</property>
-->
<!-- 扫描包下面的java文件 -->
<property name="packagesToScan">
<list>
<value>cqvie.yjq.model</value>
</list>
</property> <!-- 配置 hibernate.cfg.xml 中的信息 -->
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.format_sql">true</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
</props>
</property>
</bean> <!-- ************************************************************************************************ -->
<!-- 事务管理器 -->
<bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
</bean> <!-- 注解方式
<tx:annotation-driven transaction-manager="txManager"/>
-->
<!-- XML方式 -->
<aop:config>
<aop:pointcut expression="execution(public * cqvie.yjq.service..*.*(..))" id="bussinessService"/>
<aop:advisor pointcut-ref="bussinessService" advice-ref="txAdvice"/>
</aop:config> <tx:advice id="txAdvice" transaction-manager="txManager">
<tx:attributes>
<tx:method name="is*" read-only="true"/>
<tx:method name="add*" propagation="REQUIRED"/>
</tx:attributes>
</tx:advice> <!-- ************************************************************************************************ -->
<!-- Spring 调用 Hibernate 的持久化操作 -->
<bean id="hibernateTemplate" class="org.springframework.orm.hibernate4.HibernateTemplate">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean> </beans>

web.xml文件配置如下

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0"> <display-name>SSH_170324</display-name> <welcome-file-list>
<welcome-file>login.jsp</welcome-file>
</welcome-file-list> <listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
<!-- 默认路径:/WEB-INF/applicationContext.xml -->
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<!-- <param-value>/WEB-INF/applicationContext*.xml</param-value> -->
<param-value>classpath:beans.xml</param-value>
</context-param> <!-- Spring 解决中文乱码问题 -->
<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>
</filter>
<filter-mapping>
<filter-name>encodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping> <!-- 增加session的使用范围 -->
<filter>
<filter-name>openSessionInView</filter-name>
<filter-class>org.springframework.orm.hibernate4.support.OpenSessionInViewFilter</filter-class>
<!-- 默认寻找beans.xml中的sessionFactory -->
<init-param>
<param-name>sessionFactoryBeanName</param-name>
<param-value>sessionFactory</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>openSessionInView</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping> <!-- 配置struts2 -->
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping> </web-app>

Spring整合Hibernate的XML文件配置,以及web.xml文件配置的更多相关文章

  1. spring 整合 hibernate xml配置

    spring 整合 hibernate: hibernate :对数据库交互 spring: ioc   aop 整合点: 1.sessionFactory对象不再由hibernate生成,交由spr ...

  2. Spring整合Hibernate的时候使用hibernate.cfg.xml

    Spring整合Hibernate其实也就是把Hibernate的SessionFactory对象封装成:org.springframework.orm.hibernate3.LocalSession ...

  3. 二 SSH整合:Spring整合Hibernate,无障碍整合&无核心配置整合,Hibernate模版常用方法,

    重建SSH项目 java项目可以直接复制,但是web项目除了改名字还要该配置,如下: 方式一:无障碍整合:带Hibernate配置文件 <?xml version="1.0" ...

  4. 【Java EE 学习 53】【Spring学习第五天】【Spring整合Hibernate】【Spring整合Hibernate、Struts2】【问题:整合hibernate之后事务不能回滚】

    一.Spring整合Hibernate 1.如果一个DAO 类继承了HibernateDaoSupport,只需要在spring配置文件中注入SessionFactory就可以了:如果一个DAO类没有 ...

  5. spring整合hibernate的详细步骤

    Spring整合hibernate需要整合些什么? 由IOC容器来生成hibernate的sessionFactory. 让hibernate使用spring的声明式事务 整合步骤: 加入hibern ...

  6. Spring 整合 Hibernate

    Spring 整合 Hibernate •Spring 支持大多数流行的 ORM 框架, 包括 Hibernate JDO, TopLink, Ibatis 和 JPA. •Spring 对这些 OR ...

  7. 使用Spring整合Hibernate,并实现对数据表的增、删、改、查的功能

    1.1 问题 使用Spring整合Hibernate,并实现资费表的增.删.改.查. 1.2 方案 Spring整合Hibernate的步骤: 1.3 步骤 实现此案例需要按照如下步骤进行. 采用的环 ...

  8. Spring整合Hibernate详细步骤

    阅读目录 一.概述 二.整合步骤 回到顶部 一.概述 Spring整合Hibernate有什么好处? 1.由IOC容器来管理Hibernate的SessionFactory 2.让Hibernate使 ...

  9. SSH整合之spring整合hibernate

    SSH整合要导入的jar包: MySQL中创建数据库 create database ssh_db; ssh_db 一.spring整合hibernate带有配置文件hibernate.cfg.xml ...

随机推荐

  1. KVM NAT网络模式配置

    NAT方式原理 NAT方式是kvm安装后的默认方式.它支持主机与虚拟机的互访,同时也支持虚拟机访问互联网,但不支持外界访问虚拟机. 检查当前的网络设置: #virsh net-list --all N ...

  2. Win(Phone)10开发第(5)弹,本地媒体服务器的一些注意事项

    首先有个wp上的http服务器 http://wphttpserver.codeplex.com/ 使用方式: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 ...

  3. Centos 7 GCC 7.3编译器安装方法及C++17标准测试示例

    1.下载gcc-7.3.0源码 http://mirror.linux-ia64.org/gnu/gcc/releases/gcc-7.3.0/ 2.下载编译依赖 [root@localhost ~] ...

  4. Mac OS 10.12 - 如何能够像在Windows一样切换中英文输入法和大小写键?

    最开始,我切换中英文输入法和大小写键是按照下面博客做到的: http://www.cnblogs.com/sunylat/p/6415563.html 但是当我安装完毕搜狗输入法后,切换中英文输入法和 ...

  5. Python 第三方包上传至 PyPI 服务器

    PyPI 服务器主要功能是?PyPI 服务器怎么搭建? PyPI 服务器可以用来管理自己开发的 Python 第三包. Pypi服务器搭建 Python 第三方包在本地打包 # 本地目录执行以下命令应 ...

  6. matplotlib实现三维柱状图

    matplotlib实现三维柱状图 import cv2 img = cv2.imread("1.png", 0) #特征点在图片中的坐标位置 m = 448 n = 392 im ...

  7. QQ个人信息保护 | 攻的对面叫防

    近来我们愈来愈重视个人信息保护,当接到骚扰电话时,你心里或许在想(我手机号怎么又被别人知道的?别人是怎么知道我手机号的?),现在的时代,手机已或不可缺,QQ几乎每个人都在用.而有些人总想保护个人QQ资 ...

  8. 【OpenCV3】cvRound()、cvFloor()、cvCeil()函数详解

    函数cvRound().cvFloor().cvCeil()都是按照一种舍入方式将浮点型数据转换为整型数据. cvRound():返回跟参数最接近的整数值,即四舍五入: cvFloor()  :返回不 ...

  9. 【原创】SSRS (SQL Serve Reporting Service) 访问权限的问题

    问题:The permissions granted to user 'TOUCHPOINTMED\sshi' are insufficient for performing this operati ...

  10. Opserver 初探一《Opserver的搭建》

    Opserver 是Stack Overflow的开源监控产品.stackoverflow网站是基于asp.net开发的,具体采用的软硬件配置可以查看<StackOverflow 这么大,究竟用 ...