81,091
社区成员
发帖
与我相关
我的任务
分享
<?xml version="1.0" encoding="UTF-8"?>
<!-- 数据库相关 -->
<beans xmlns="http://www.springframework.org/schema/beans"
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-2.0.xsd"
default-autowire="byName">
<!-- 数据库的hibernate配置 -->
<bean id="dataSource"
class="com.mchange.v2.c3p0.ComboPooledDataSource"
destroy-method="close">
<property name="driverClass"
value="oracle.jdbc.driver.OracleDriver">
</property>
<property name="jdbcUrl"
value="jdbc:oracle:thin:@12.61.14.61:1521:KPI">
</property>
<property name="user" value="user"></property>
<property name="password" value="pass"></property>
<property name="maxPoolSize" value="40" />
<!-- 指定连接数据库连接池的最小连接数 -->
<property name="minPoolSize" value="1" />
<!-- 指定连接数据库连接池的初始化连接数 -->
<property name="initialPoolSize" value="1" />
<!-- 指定连接数据库连接池的连接的最大空闲时间 -->
<property name="maxIdleTime" value="20" />
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource"></ref>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.Oracle9Dialect
</prop>
<prop key="hibernate.show_sql">false</prop>
<prop key="format_sql">true</prop>
</props>
</property>
<property name="mappingResources">
<list>
<value>
com/rdc/hibernate/bean/Processkpcontract.hbm.xml
</value>
...........
</list>
</property>
</bean>
<!-- 声明services -->
<bean id="service" class="com.rdc.struts.service.ServicesImpl"></bean>
<bean id="serviceC" class="com.rdc.struts.service.ServicesImpl_C"></bean>
<bean id="serviceL" class="com.rdc.struts.service.ServicesImpl_L"></bean>
<bean id="serviceZ" class="com.rdc.struts.service.ServicesImpl_Z"></bean>
<bean id="serviceF" class="com.rdc.struts.service.ServicesImpl_F"></bean>
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
<!-- 事务拦截器 -->
<bean id="transactionInterceptor"
class="org.springframework.transaction.interceptor.TransactionInterceptor">
<property name="transactionManager" ref="transactionManager" />
<property name="transactionAttributes">
<props>
<prop key="insert*">PROPAGATION_REQUIRED</prop>
<prop key="find*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="*">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>
<bean
class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
<property name="beanNames">
<list>
<value>service</value>
<value>serviceC</value>
<value>serviceL</value>
<value>serviceZ</value>
<value>serviceF</value>
</list>
</property>
<property name="interceptorNames">
<value>transactionInterceptor</value>
</property>
<property name="proxyTargetClass">
<value>true</value>
</property>
</bean>
<bean name="daoTemplate" abstract="true">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
.........................
</beans>
public class AchieveevaluateDAO extends HibernateDaoSupport {
public void save(Achieveevaluate transientInstance) {
try {
getHibernateTemplate().save(transientInstance);
} catch (RuntimeException re) {
throw re;
}
}
}
<!--hibernate事务管理 -->
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<bean name="daoTemplate" abstract="true">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="achieveevaluateDAO"
class="com.rdc.hibernate.dao.AchieveevaluateDAO" parent="daoTemplate">
</bean>
<!--hibernate事务管理 -->
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<bean name="daoTemplate" abstract="true">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean name="daoTemplate" abstract="true">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
package com.rdc.hibernate.dao;
import java.util.Date;
import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.springframework.context.ApplicationContext;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import com.rdc.hibernate.bean.Achieveevaluate;
/**
* Data access object (DAO) for domain model class Achieveevaluate.
*
* @see com.rdc.hibernate.bean.Achieveevaluate
* @author MyEclipse Persistence Tools
*/
public class AchieveevaluateDAO extends HibernateDaoSupport {
public void save(Achieveevaluate transientInstance) {
log.debug("saving Achieveevaluate instance");
try {
getHibernateTemplate().save(transientInstance);
log.debug("save successful");
} catch (RuntimeException re) {
log.error("save failed", re);
throw re;
}
}
public void update(Achieveevaluate transientInstance) {
log.debug("updating Achieveevaluate instance");
try {
getHibernateTemplate().update(transientInstance);
log.debug("update successful");
} catch (RuntimeException re) {
log.error("update failed", re);
throw re;
}
}
}
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
TO:-------------->
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<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:p="http://www.springframework.org/schema/p"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">
......
<?xml version="1.0" encoding="UTF-8"?>
<!-- 数据库相关 -->
<beans xmlns="http://www.springframework.org/schema/beans"
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-2.0.xsd"
default-autowire="byName">
<!-- 数据库的hibernate配置 -->
......
<!-- 声明services -->
<bean id="service" class="com.rdc.struts.service.ServicesImpl"></bean>
<bean id="serviceC" class="com.rdc.struts.service.ServicesImpl_C"></bean>
<bean id="serviceL" class="com.rdc.struts.service.ServicesImpl_L"></bean>
<bean id="serviceZ" class="com.rdc.struts.service.ServicesImpl_Z"></bean>
<bean id="serviceF" class="com.rdc.struts.service.ServicesImpl_F"></bean>
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
</bean>
<tx:advice id="txAdvice">
<tx:attributes>
<tx:method name="insert*"propagation="REQUIRED"/>
<tx:method name="find*"propagation="REQUIRED" read-only="true"/>
<tx:method name="*"propagation="REQUIRED"/>
</tx:attributes>
</tx:advice>
<aop:config>
<aop:pointcut id="fooServiceOperation"
expression="execution(* com.rdc.struts.service.*.*(..))" />
<aop:advisor advice-ref="txAdvice"
pointcut-ref="fooServiceOperation" />
</aop:config>
<bean name="daoTemplate" abstract="true">
</bean>
.........................
</beans>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<!-- 非JNDI数据源配置 -->
<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName">
<value>oracle.jdbc.driver.OracleDriver</value>
</property>
<property name="url">
<value>jdbc:oracle:thin:@localhost:1521:oemrep</value>
</property>
<property name="username">
<value>test</value>
</property>
<property name="password">
<value>test</value>
</property>
</bean>
<!-- JNDI数据源配置
<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName">
<value>demoDS</value>
</property>
</bean>-->
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<!-- JTA事务管理的配置
<property name="jtaTransactionManager">
<ref bean="webLogicServerTransactionManagerFactory"/>
</property>-->
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.Oracle9Dialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.cglib.use_reflection_optimizer">false</prop>
<prop key="hibernate.jdbc.fetch_size">50</prop>
<prop key="hibernate.jdbc.batch_size">20</prop>
<prop key="hibernate.query.factory_class">org.hibernate.hql.classic.ClassicQueryTranslatorFactory</prop>
<!-- <prop key="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</prop>
<prop key="hibernate.cache.use_query_cache">true</prop> -->
</props>
</property>
<property name="mappingDirectoryLocations">
<list>
<!-- 添加hibernate值对象的路径名 -->
<value>classpath:/com/htxx/demo/model</value>
</list>
</property>
</bean>
<!--hibernate事务管理 -->
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<bean id="transactionManagerJDBC" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource">
<ref local="dataSource"/>
</property>
</bean>
<!-- JtaTransactionManager不需要知道 DataSource 和其他特定的资源,因为它将使用容器提供的全局事务管理
<bean id="jtaTransactionManager" class="org.springframework.transaction.jta.JtaTransactionManager">
<property name="userTransaction"><ref bean="webLogicServerTransactionManagerFactory"/></property>
</bean>-->
<!-- WebLogic服务器事务管理工厂
<bean id="webLogicServerTransactionManagerFactory" class="org.springframework.transaction.jta.WebLogicServerTransactionManagerFactoryBean">
</bean>-->
<!-- 事务拦截器 -->
<bean id="transactionInterceptor"
class="org.springframework.transaction.interceptor.TransactionInterceptor">
<property name="transactionManager" ref="transactionManager" />
<property name="transactionAttributeSource"><ref bean="defaultTxAttributes"/></property>
</bean>
<!-- 事务属性源 -->
<bean id="defaultTxAttributes"
class="org.springframework.transaction.interceptor.NameMatchTransactionAttributeSource">
<property name="properties">
<props>
<prop key="create*">PROPAGATION_REQUIRED</prop>
<prop key="delete*">PROPAGATION_REQUIRED</prop>
<prop key="update*">PROPAGATION_REQUIRED</prop>
<prop key="modify*">PROPAGATION_REQUIRED</prop>
<prop key="*">PROPAGATION_REQUIRED,readOnly</prop>
</props>
</property>
</bean>
<bean id="InvoiceTxAttributes"
class="org.springframework.transaction.interceptor.NameMatchTransactionAttributeSource">
<property name="properties">
<props>
<prop key="create*">PROPAGATION_REQUIRED</prop>
<prop key="delete*">PROPAGATION_REQUIRED</prop>
<prop key="update*">PROPAGATION_REQUIRED</prop>
<prop key="cancel*">PROPAGATION_REQUIRED</prop>
<prop key="accountIn">PROPAGATION_REQUIRED</prop>
<prop key="accountOut">PROPAGATION_REQUIRED</prop>
<prop key="*">PROPAGATION_SUPPORTS</prop>
</props>
</property>
</bean>
<!-- 名称匹配的自动代理创建器,所有名字以Bus,Service结尾的bean都将为其创建事务拦截,注释此处就不再被自动事务处理 -->
<bean name="beanNameAutoProxyCreator" class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
<property name="beanNames">
<value>*Bus,*Service</value>
</property>
<property name="interceptorNames">
<list>
<!-- 可以增加其他的拦截器 -->
<value>transactionInterceptor</value>
</list>
</property>
</bean>
<!-- ehcache缓存处理 -->
<!-- <bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
<property name="configLocation">
<value>classpath:ehcache.xml</value>
</property>
</bean>
<bean id="methodCache" class="org.springframework.cache.ehcache.EhCacheFactoryBean">
<property name="cacheManager">
<ref local="cacheManager"/>
</property>
<property name="cacheName">
<value>defaultCache</value>
</property>
</bean> -->
</beans>