spring配置文件如下:
<!-- 导入nutzboot的spring定义 -->
<bean id="nutz.uflo.helper" class="cn.com.unis.uflo.utils.UfloHelper" />
<bean id="nutz.dataSource" class="javax.sql.DataSource" factory-bean="nutz.uflo.helper" factory-method="getDataSource"/>
<bean id="nutz.conf" class="org.nutz.ioc.impl.PropertiesProxy" factory-bean="nutz.uflo.helper" factory-method="getPropertiesProxy"/>
<bean id="nutz.spring.propertyPlaceHolder" class="cn.com.unis.uflo.utils.Nutz2SpringPropertyPlaceholder">
<property name="conf" ref="nutz.conf"></property>
</bean>
<import resource="classpath:uflo-console-context.xml" />
<bean id="uflo.environmentProvider" class="cn.com.unis.uflo.utils.UfloEnvironmentProvider" factory-method="getSelf">
<property name="platformTransactionManager" ref="uflo.transactionManager" />
<property name="sessionFactory" ref="uflo.sessionFactory" />
</bean>
<bean id="uflo.sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="nutz.dataSource" />
<property name="packagesToScan">
<list>
<value>com.bstek.uflo.model*</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.dialect">org.hibernate.dialect.DmDialect</prop>
<prop key="hibernate.hbm2ddl.auto">none</prop>
</props>
</property>
</bean>
<bean id="uflo.transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="uflo.sessionFactory"/>
</bean>
<bean id="springDaoRunner" class="cn.com.unis.uflo.plugin.SpringDaoRunner"></bean>
<bean id="nutDao" class="org.nutz.dao.impl.NutDao">
<property name="dataSource" ref="nutz.dataSource"/>
<property name="runner" ref="springDaoRunner"/>
</bean>
<bean id="officialService" class="cn.com.unis.uflo.service.impl.OfficialServiceImpl" factory-method="getSelf">
<property name="dao" ref="nutDao"></property>
<property name="transactionManager" ref="uflo.transactionManager"></property>
</bean>
<bean id="signReportAction" class="cn.com.unis.uflo.action.SignReportAction" factory-method="getSelf">
<property name="officialService" ref="officialService"></property>
</bean>
service实现类如下:
@IocBean(name = "officialService",factory="cn.com.unis.uflo.service.impl.OfficialServiceImpl#getSelf")
public class OfficialServiceImpl extends BaseServiceImpl implements IOfficialService{
private static IOfficialService officialService = new OfficialServiceImpl();
@Inject
private ProcessService processService;
@Inject
private TaskService taskService;
private PlatformTransactionManager transactionManager;
public static IOfficialService getSelf() {
return officialService;
}
public void setDao(Dao dao) {
this.dao = dao;
}
public PlatformTransactionManager getTransactionManager() {
return transactionManager;
}
public void setTransactionManager(PlatformTransactionManager transactionManager) {
this.transactionManager = transactionManager;
}
//事务未生效方法
@Transactional
public void SignDraft(SignReport signReport,String[] handler,String divisionLeader,String processKey) {
ProcessInstance instance = getProcessInstance(signReport.getId());
signReport.setDocHead("测试事务");
Long currentTaskId = null;
if(instance == null){
//开启流程
ProcessInstance processInstance = startProcess(null, Long.parseLong(processKey), signReport.getId());
signReport.setProcessId(processInstance.getId());
currentTaskId = getCurrentTaskId(signReport.getId(), CommonUtil.getUserCode());
insertContainAllLinks(signReport);
}else{
currentTaskId = getCurrentTaskId(signReport.getId(), CommonUtil.getUserCode());
updateSignReportAllLinks(signReport);
}
Map<String,Object> variables = new HashMap<String, Object>();
if(handler != null && handler.length > 0){
variables.put(Constant.handlerKey, Arrays.asList(handler));
variables.put(Constant.signRepSponsorDepeHeadKey, Arrays.asList(handler));
}
variables.put(Constant.divisionLeaderKey, divisionLeader);
variables.put(Constant.starterKey, CommonUtil.getUserCode());
variables.put(Constant.deptCodeKey, CommonUtil.getDeptCode());
int i = 1/0;
startAndCompleteTask(currentTaskId, variables);
}
}
action如下:
@IocBean(factory="cn.com.unis.uflo.action.SignReportAction#getSelf")
@At({"/signReport"})
public class SignReportAction extends CommonAction{
private final Log log = Logs.getLog(getClass());
private static CommonAction signReportAction = new SignReportAction();
private String processKey = "128353";
private IOfficialService officialService;
public static CommonAction getSelf() {
return signReportAction;
}
public IOfficialService getOfficialService() {
return officialService;
}
public void setOfficialService(IOfficialService officialService) {
this.officialService = officialService;
}
@At("/completeDraft")
@Aop({"processLogInterceptor"})
@ProcessLogAnno(operationType ="发起签报", processType = Constant.SIGN_REPORT_PROCESS_TYPE)
public Object completeDraft(@Param("::s.")SignReport signReport,String[] handler,String divisionLeader){
try {
signReport = officialService.preUpdateSignReportLinks(signReport);
signReport.setStatus(SignReportStatus.approv.val());
officialService.SignDraft(signReport, handler, divisionLeader, processKey);
return LayUtil.success();
} catch (Exception e) {
if(log.isErrorEnabled()) {
log.errorf("流程更新失败:%s", new Object[] { e.getMessage() });
}
return LayUtil.fail("流程更新失败:" + e.getMessage());
}
}
}