spring 配置文件 app-context.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsp="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsp:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">
<bean id="manuPlanNewDaoImpl" class="manuPlanNew.service.dao.ManuPlanDaoImpl"
parent="daoTemplate.flm">
</bean>
<bean id="manuPlanNewServiceImpl" class="manuPlanNew.service.ManuPlanServiceImpl">
<property name="manuPlanDao">
<ref bean="manuPlanNewDaoImpl" />
</property>
<property name="txManager">
<ref bean="txManager" />
</property>
</bean>
<bean id="manuPlanNewAction" class="manuPlanNew.action.ManuPlanAction" scope="prototype">
<property name="manuPlanService">
<ref bean="manuPlanNewServiceImpl" />
</property>
</bean>
<bean id="manuPlanEntryNewAction" class="manuPlanNew.action.ManuPlanEntryAction" scope="prototype">
<property name="manuPlanService">
<ref bean="manuPlanNewServiceImpl" />
</property>
<property name="categoryService">
<ref bean="categoryServiceImpl"/>
</property>
</bean>
</beans>
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:jee="http://www.springframework.org/schema/jee"
xmlns="http://www.springframework.org/schema/beans"
xsi:schemaLocation="http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<import resource="classpath*:**/*-context.xml"/>
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="classpath:jdbc.properties"/>
</bean>
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="${driverClassName}"/>
<property name="defaultAutoCommit" value="${defaultAutoCommit}"/>
<property name="url" value="${url}"/>
<property name="username" value="${username}"/>
<property name="password" value="${password}"/>
<property name="maxActive" value="${maxActive}"/>
<property name="maxIdle" value="${maxIdle}"/>
<property name="maxWait" value="${maxWait}"/>
</bean>
<bean id="sqlMapClient" class="common.ibatis.SimpleSqlMapClientFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="sqlMapLocations" value="classpath*:**/*sqlmap.xml"/>
<property name="statementCachingEnabled" value="true"/>
<property name="cacheModelsEnabled" value="true"/>
<property name="useStatementNamespaces" value="true"/>
</bean>
<bean id="sqlMapClientTemplate" class="common.ibatis.NewLifeSqlMapClientTemplate">
<property name="outputLog" value="true"/>
<property name="sqlMapClient" ref="sqlMapClient"/>
</bean>
<bean id="daoTemplate.flm" scope="prototype" abstract="true"
class="org.springframework.orm.ibatis.support.SqlMapClientDaoSupport">
<property name="sqlMapClientTemplate" ref="sqlMapClientTemplate"/>
</bean>
<bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
</bean>
<alias name="daoTemplate.flm" alias="daoTemplate.com"/>
<alias name="daoTemplate.flm" alias="daoTemplate.axs"/>
<alias name="daoTemplate.flm" alias="daoTemplate.fop"/>
<alias name="daoTemplate.flm" alias="daoTemplate.ext"/>
<alias name="daoTemplate.flm" alias="daoTemplate.fli"/>
</beans>
service层 方法
public String insertManuPlan(ManuPlan manuPlan) {
// 建立事务
DefaultTransactionDefinition def = new DefaultTransactionDefinition();
def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
def.setTimeout(12000);
String id=null;
TransactionStatus status = txManager.getTransaction(def);
try {
id=this.manuPlanDao.insertManuPlan(manuPlan);
} catch(RuntimeException e) {
txManager.rollback(status);
throw e;
}
txManager.commit(status);
return id;
}