将我的应用程序与Activiti集成

时间:2016-05-17 06:54:39

标签: spring activiti vaadin-spring-boot

我有一个问题。我将我的应用程序与Activiti集成(在同一个数据库中)。当我插入,更新或删除我的实体(不是实体的活动)时,Dao类使用@Transactional但没有任何关于保存到数据库的情况,没有例外。

这是我的集成配置:

 @Configuration
public class ActivitiEngineConfiguration {

  private final Logger log = LoggerFactory.getLogger(ActivitiEngineConfiguration.class);

  @Autowired
  protected Environment environment;

  @Bean
  public DataSource dataSource() { 
    SimpleDriverDataSource ds = new SimpleDriverDataSource();

    try {
      @SuppressWarnings("unchecked")
      Class<? extends Driver> driverClass = (Class<? extends Driver>) Class.forName(environment.getProperty("jdbc.driver", "org.postgresql.Driver"));
      ds.setDriverClass(driverClass);

    } catch (Exception e) {
      log.error("Error loading driver class", e);
    }

    ds.setUrl(environment.getProperty("spring.datasource.url"));
    ds.setUsername(environment.getProperty("spring.datasource.username"));
    ds.setPassword(environment.getProperty("spring.datasource.password"));

    return ds;
  }


  @Bean(name = "transactionManager")
  public PlatformTransactionManager annotationDrivenTransactionManager() {
    DataSourceTransactionManager transactionManager = new DataSourceTransactionManager();
    transactionManager.setDataSource(dataSource());
    System.out.println("transactionManager: "+transactionManager);
    return transactionManager;
  }


  @Bean(name="processEngineFactoryBean")
  public ProcessEngineFactoryBean processEngineFactoryBean() {
    ProcessEngineFactoryBean factoryBean = new ProcessEngineFactoryBean();
    factoryBean.setProcessEngineConfiguration(processEngineConfiguration());
    return factoryBean;
  }

  @Bean(name="processEngine")
  public ProcessEngine processEngine() {
    // Safe to call the getObject() on the @Bean annotated processEngineFactoryBean(), will be
    // the fully initialized object instanced from the factory and will NOT be created more than once
    try {
      return processEngineFactoryBean().getObject();
    } catch (Exception e) {
      throw new RuntimeException(e);
    }
  }

  @Bean(name="processEngineConfiguration")
  public ProcessEngineConfigurationImpl processEngineConfiguration() {
    SpringProcessEngineConfiguration processEngineConfiguration = new SpringProcessEngineConfiguration();
    processEngineConfiguration.setDataSource(dataSource());
    processEngineConfiguration.setDatabaseSchemaUpdate(environment.getProperty("engine.schema.update", "true"));
    processEngineConfiguration.setTransactionManager(annotationDrivenTransactionManager());
    processEngineConfiguration.setJobExecutorActivate(Boolean.valueOf(
        environment.getProperty("engine.activate.jobexecutor", "false")));
    processEngineConfiguration.setAsyncExecutorEnabled(Boolean.valueOf(
        environment.getProperty("engine.asyncexecutor.enabled", "true")));
    processEngineConfiguration.setAsyncExecutorActivate(Boolean.valueOf(
        environment.getProperty("engine.asyncexecutor.activate", "true")));
    processEngineConfiguration.setHistory(environment.getProperty("engine.history.level", "full"));

    String mailEnabled = environment.getProperty("engine.email.enabled");
    if ("true".equals(mailEnabled)) {
      processEngineConfiguration.setMailServerHost(environment.getProperty("engine.email.host"));
      int emailPort = 1025;
      String emailPortProperty = environment.getProperty("engine.email.port");
      if (StringUtils.isNotEmpty(emailPortProperty)) {
        emailPort = Integer.valueOf(emailPortProperty);
      }
      processEngineConfiguration.setMailServerPort(emailPort);
      String emailUsernameProperty = environment.getProperty("engine.email.username");
      if (StringUtils.isNotEmpty(emailUsernameProperty)) {
        processEngineConfiguration.setMailServerUsername(emailUsernameProperty);
      }

      String emailPasswordProperty = environment.getProperty("engine.email.password");
      if (StringUtils.isNotEmpty(emailPasswordProperty)) {
        processEngineConfiguration.setMailServerPassword(emailPasswordProperty);
      }
    }

//      List<AbstractFormType> formTypes = new ArrayList<AbstractFormType>();
//      formTypes.add(new UserFormType());
//      formTypes.add(new ProcessDefinitionFormType());
//      formTypes.add(new MonthFormType());
//      processEngineConfiguration.setCustomFormTypes(formTypes);

    return processEngineConfiguration;
  }

  @Bean
  public RepositoryService repositoryService() {
    return processEngine().getRepositoryService();
  }

  @Bean
  public RuntimeService runtimeService() {
    return processEngine().getRuntimeService();
  }

  @Bean
  public TaskService taskService() {
    return processEngine().getTaskService();
  }

  @Bean
  public HistoryService historyService() {
    return processEngine().getHistoryService();
  }

  @Bean
  public FormService formService() {
    return processEngine().getFormService();
  }

  @Bean
  public IdentityService identityService() {
    return processEngine().getIdentityService();
  }

  @Bean
  public ManagementService managementService() {
    return processEngine().getManagementService();
  }
}

DAO Layer:

@Autowired
private SessionFactory sessionFactory;

@Override
@Transactional
public void save(MyEntity obj) {
    sessionFactory.getCurrentSession().saveOrUpdate(loaiDanhMuc);
}

谢谢大家!

1 个答案:

答案 0 :(得分:0)

我猜@Transactional在这种情况下不起作用

请检查以下内容:

  1. 检查spring xml文件中是否定义了<tx:annotation-driven />