日期:2014-05-19 浏览次数:20763 次
<aop:aspectj-autoproxy/> <context:component-scan base-package="net.orc,com.spring3"/> <context:property-placeholder location="classpath:jdbc.properties"/> <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close"> <property name="driverClass" value="${driverClass}"/> <property name="jdbcUrl" value="${jdbcUrl}"/> <property name="user" value="${user}"/> <property name="password" value="${password}"/> <property name="initialPoolSize" value="1"/> <property name="minPoolSize" value="1"/> <property name="maxPoolSize" value="300"/> <property name="maxIdleTime" value="60"/> <!-- 当连接池中的连接耗尽的时候c3p0一次同时获取的连接数。Default: 3 --> <property name="acquireIncrement" value="5"/> <!-- 每60秒检查所有连接池中的空闲连接。Default: 0 --> <property name="idleConnectionTestPeriod" value="60"/> </bean> <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"> <property name="dataSource" ref="dataSource"/> <property name="persistenceXmlLocation" value="classpath:META-INF/persistence.xml" /> <property name="loadTimeWeaver"> <bean class="org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver"/> </property> </bean> <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"> <property name="entityManagerFactory" ref="entityManagerFactory"/> </bean> <tx:annotation-driven transaction-manager="transactionManager"/>
package net.orc.service.base; import javax.persistence.EntityManager; import javax.persistence.PersistenceContext; import org.springframework.transaction.annotation.Transactional; @SuppressWarnings("unchecked") @Transactional public abstract class DaoSupport<T> implements DAO<T>{ @PersistenceContext protected EntityManager em; public void save(T entity) { em.persist(entity); } public void update(T entity) { em.merge(entity); } }