xml配置
- XML code
<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"/>
dao
- Java code
package net.orc.service.base;import javax.persistence.EntityManager;import javax.persistence.PersistenceContext;import org.springframework.transaction.annotation.Transactional;@SuppressWarnings("unchecked")@Transactionalpublic 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); }}
过来的朋友帮忙看看
------解决方案--------------------
是用spring-mvc 吗?,
事物不生效?
你看看
http://blog.csdn.net/zuxianghuang/article/details/6649269
------解决方案--------------------
关键是这个
12. <context:component-scan base-package="com.spring3">
13. <!-- 将Service注解给去掉 --> 14. <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
15. <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Service"/>
16. </context:component-scan>
17. <context:annotation-config />
------解决方案--------------------
12. <context:component-scan base-package="com.spring3">
13. <!-- 将Service注解给去掉 --> 14. <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>