spring 配置hibernate
来源:互联网 发布:中国联合网络通信电话 编辑:程序博客网 时间:2024/05/24 01:30
spring配置hibernate的配置文件
<?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:aop="http://www.springframework.org/schema/aop"xmlns:tx="http://www.springframework.org/schema/tx"xmlns:context="http://www.springframework.org/schema/context"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd"><!-- 为了系统识别相应的注解 --><!--也是用于激活那些已经在spring容器里注册过的bean(无论是通过xml的方式 --><!-- 还是通过package sanning的方式)上面的注解。 --><context:annotation-config /><!--配置扫描包的路径,包含其子包 --><context:component-scan base-package="com.XXX"></context:component-scan><!--读取外部属性文件 --><context:property-placeholder location="classpath:db.properties" /><!-- 使用c3p0接收属性 --><bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"><property name="user" value="${jdbc.user}"></property><property name="password" value="${jdbc.password}"></property><property name="driverClass" value="${jdbc.driverClass}"></property><property name="jdbcUrl" value="${jdbc.jdbcUrl}"></property><property name="initialPoolSize" value="${jdbc.initPoolSize}"></property><property name="maxPoolSize" value="${jdbc.maxPoolSize}"></property></bean><!--用Spring帮你创建hibernate的SessionFactory(注解方式) --><bean id="sessionFactory"class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"><property name="dataSource" ref="dataSource" /><!-- 方式一<property name="annotatedClasses"><list><value>com.XXX</value><value>com.XXX</value></list></property> --> <!--方式二、 可以自动扫描list中指定的包来加载实体类,不用一 一指明 --> <property name="packagesToScan"><list><value>com.XXX</value></list></property><property name="hibernateProperties"><props><prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop><prop key="hibernate.show_sql">true</prop></props></property></bean><!--hibernateTemplate封装了一系列的方法,比如save,update,等 --><bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate"><property name="sessionFactory" ref="sessionFactory"></property></bean><!-- 定义事务管理器 --><bean id="txManager"class="org.springframework.orm.hibernate3.HibernateTransactionManager"><property name="sessionFactory" ref="sessionFactory" /></bean><!-- 配置参与事务的类 --><aop:config><!-- 切面配置,aop:pointcut标签配置参与事务的类,由于是在Service中进行数据库业务操作, --><!-- 配的应该是包含那些作为事务的方法的Service类。 --><aop:pointcut id="bussinessService"expression="execution(public * com.XXX.*.*(..))" /><!--aop:advisor标签就是把上面我们所配置的事务管理两部分属性整合起来作为整个事务管理。 --><aop:advisor pointcut-ref="bussinessService"advice-ref="txAdvice" /></aop:config><!-- 事务的传播特性 --><tx:advice id="txAdvice" transaction-manager="txManager"><!--tx:attribute标签所配置的是作为事务的方法的命名类型 --><tx:attributes><tx:method name="XXX" read-only="true" /><!--propagation="REQUIRED"代表支持当前事务,如果当前没有事务,就新建一个事务 --><tx:method name="XXX" propagation="REQUIRED"/></tx:attributes></tx:advice></beans>
0 0
- 配置Struts+spring+hibernate
- Spring+Hibernate配置事务
- Spring+Hibernate+Struts配置
- Spring+Hibernate+Proxool配置
- spring+hibernate+struts配置
- spring hibernate 事务配置
- hibernate+spring配置
- spring+hibernate的配置
- Spring+Hibernate+WebWork配置
- hibernate+spring配置详解
- Spring+Hibernate 整合配置
- Spring + dwr + Hibernate 配置
- Struts+Hibernate+Spring 配置
- spring+hibernate缓存配置
- hibernate+spring 配置详解
- Spring+Hibernate整合配置
- spring+hibernate+aAtomikos 配置
- Spring,hibernate数据库连接配置
- Android Annotations 介绍
- ArrayComm宣布推出BasePort高性能可扩展LTE基站物理层软件和测试工具
- 杭电OJ Fibonacci Again
- 1.2 移动网络注册
- servlet学习笔记之序言
- spring 配置hibernate
- SpringMVC Controller 返回值几种类型
- 如何在Eclipse中如何自动添加注释和自定义注释风格
- 1.3 设置APN
- R语言做文本挖掘 Part2分词处理
- 正则表达式把用逗号分开的字符串转换成数组
- JavaScript父子窗口互传数据
- 隐藏域的作用
- 关于华为code craft比赛算法(遗传算法)