Spring2 Hibernate3 Junit 应用示例5
原创
©著作权归作者所有:来自51CTO博客作者xhcat1025的原创作品,请联系作者获取转载授权,否则将追究法律责任
<1>、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:jee="http://www.springframework.org/schema/jee"
xsi:schemaLocation="http://www.springframework.org/schema/beans
[url]http://www.springframework.org/schema/beans/spring-beans-2.0.xsd[/url]
[url]http://www.springframework.org/schema/jee[/url] [url]http://www.springframework.org/schema/jee/spring-jee-2.0.xsd[/url]">
<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName">
<value>com.mysql.jdbc.Driver</value>
</property>
<property name="url">
<value>jdbc:mysql://192.168.3.110:3306/DBName?useUnicode=true&characterEncoding=GBK</value>
</property>
<property name="username">
<value>root</value>
</property>
<property name="password">
<value>root</value>
</property>
</bean>
<!-- Hibernate SessionFactory -->
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref local="dataSource" />
</property>
<property name="mappingResources">
<list>
<value>com/xh/hibernate/vo/User.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.MySQLDialect
</prop>
<prop key="hibernate.show_sql">true</prop>
<!--
<prop
key="hibernate.hbm2ddl.auto">create</prop>
-->
</props>
</property>
</bean>
<!-- Transaction manager for a single
Hibernate SessionFactory (alternative to JTA) -->
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory">
<ref local="sessionFactory" />
</property>
</bean>
<!-- Add DAOs here -->
<bean id="userDAO"
class="com.xh.hibernate.dao.impl.UserDAOImpl">
<property name="sessionFactory">
<ref local="sessionFactory" />
</property>
</bean>
<!-- Add Managers here -->
<bean id="userManagerTarget"
class="com.xh.spring.service.impl.UserManagerImpl">
<property name="userDAO">
<ref local="userDAO" />
</property>
</bean>
<bean id="userManager"
class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager">
<ref local="transactionManager" />
</property>
<property name="target">
<ref local="userManagerTarget" />
</property>
<property name="transactionAttributes">
<props>
<prop key="save*">PROPAGATION_REQUIRED</prop>
<prop key="remove*">PROPAGATION_REQUIRED</prop>
<prop key="update*">PROPAGATION_REQUIRED</prop>
<prop key="*">PROPAGATION_REQUIRED,readOnly</prop>
</props>
</property>
</bean>
</beans>
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
spring3、struts2、hibernate3框架整合
http://blog.csdn.net/neareast/article/details/7457618
整合 struts2 hibernate3 spring3 -
Hibernate3综述
原理:1. 读取并解析配置文件2. 读取并解析映射信息,创建SessionFactory3. 打开Sesssio
职场 Hibernate 休闲 Hibernate 原理 缓存 对象关系