cancel
Showing results for 
Search instead for 
Did you mean: 

spring3.0.5 ActivitiException transactionManager is required

zhangmin
Champ in-the-making
Champ in-the-making
<bean id="dataSource" class="org.springframework.jdbc.datasource.TransactionAwareDataSourceProxy">
    <property name="targetDataSource">
      <bean class="org.springframework.jdbc.datasource.SimpleDriverDataSource">
        <property name="driverClass" value="com.mysql.jdbc.Driver" />
        <property name="url" value="jdbc:mysql://localhost/test" />
        <property name="username" value="root" />
        <property name="password" value="" />
      </bean>
    </property>
  </bean>

  <bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
    <property name="dataSource" ref="dataSource" />
  </bean>
 
  <bean id="processEngineConfiguration" class="org.activiti.spring.SpringProcessEngineConfiguration">
    <property name="databaseType" value="mysql" />
    <property name="dataSource" ref="dataSource" />
    <property name="transactionManager" ref="txManager" />
    <property name="databaseSchemaUpdate" value="true" />
    <property name="jobExecutorActivate" value="false" />
  </bean>
 
  <bean id="processEngine" class="org.activiti.spring.ProcessEngineFactoryBean">
    <property name="processEngineConfiguration" ref="processEngineConfiguration" />
  </bean>
  <bean id="repositoryService" factory-bean="processEngine" factory-method="getRepositoryService" />
  <bean id="runtimeService" factory-bean="processEngine" factory-method="getRuntimeService" />
  <bean id="taskService" factory-bean="processEngine" factory-method="getTaskService" />
  <bean id="historyService" factory-bean="processEngine" factory-method="getHistoryService" />
  <bean id="managementService" factory-bean="processEngine" factory-method="getManagementService" />

Caused by: org.activiti.engine.ActivitiException: transactionManager is required property for SpringProcessEngineConfiguration, use org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration otherwise
7 REPLIES 7

jbarrez
Star Contributor
Star Contributor
That looks ok.
That exception is thrown when no transactionManager is set, but that seems to be ok for you.

Could you give some more logging?

gergelydombi
Champ in-the-making
Champ in-the-making
Hi,

I experienced the same problem. The problem arose because I wanted to inject an autowired
member field (RepositoryService) to my spring managed JUnit test.
The root cause is that Activiti spring integration uses the default autowire strategy, while
I wanted to use a byType, annotation based injection to inject the repository service.

The solution:

I split the spring configuration into two pieces:

service-applicationContext.xml, that uses byType injection:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
                        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd"
                        default-autowire="byType">


<bean id="repositoryService" factory-bean="processEngine"
  factory-method="getRepositoryService" />
<bean id="runtimeService" factory-bean="processEngine"
  factory-method="getRuntimeService" />
<bean id="taskService" factory-bean="processEngine"
  factory-method="getTaskService" />
<bean id="historyService" factory-bean="processEngine"
  factory-method="getHistoryService" />
<bean id="managementService" factory-bean="processEngine"
  factory-method="getManagementService" />


</beans>

and activiti.cfg.xml, that uses direct references:


<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
                        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd"
                        >
<bean id="dataSource"
  class="org.springframework.jdbc.datasource.TransactionAwareDataSourceProxy">
  <property name="targetDataSource">
   <bean class="org.springframework.jdbc.datasource.SimpleDriverDataSource">
    <property name="driverClass"
     value="com.microsoft.sqlserver.jdbc.SQLServerDriver" />
    <property name="url" value="jdbc:sqlserver://localhost:1433" />
    <property name="username" value="user" />
    <property name="password" value="pass" />
   </bean>
  </property>
</bean>

<bean id="transactionManager"
  class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
  <property name="dataSource" ref="dataSource" />
</bean>

<bean id="processEngineConfiguration" class="org.activiti.spring.SpringProcessEngineConfiguration">


  <property name="databaseType" value="mssql" />
  <property name="dataSource" ref="dataSource" />
  <property name="transactionManager" ref="transactionManager" />
  <property name="databaseSchemaUpdate" value="false" />
  <property name="jobExecutorActivate" value="false" />
  <property name="deploymentResources" value="classpath*:/diagrams/*.bpmn20.xml" />  
 

</bean>


<bean id="processEngine" class="org.activiti.spring.ProcessEngineFactoryBean">
  <property name="processEngineConfiguration" ref="processEngineConfiguration" />
</bean>

<tx:annotation-driven transaction-manager="transactionManager" /> 

</beans>

This enables the SpringProcessEngineConfiguration to be injected as specified in the configuration.

In the JUnit test you can now reference the repository service via annotation:



@Transactional
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath:service-applicationContext.xml", "classpath:activiti.cfg.xml"})
public class ProcessTestHelloworld {

@Autowired
RepositoryService repositoryService;

@Test
public void testSpring() { 
  String deploymentId = repositoryService
    .createDeployment()
    .addClasspathResource("diagrams/demo_bpmn.activiti.bpmn20.xml")
    .deploy()
    .getId(); 
  System.out.println("*** Repository id: " + deploymentId);
}



HTH,
Gergő

jbarrez
Star Contributor
Star Contributor
So if I understand you correctly, a rename of the beans should also do the trick (if I want to keep using the default auto-wiring)?

gergelydombi
Champ in-the-making
Champ in-the-making
My understanding is that if you use default autowiring then this problem should never occur.
Only when I switched to autowire byType I saw this problem. My suggested solution keeps the activiti
autowiring strategy as is, and enables the client to use another autowiring strategy (or keep the default).

So probably that is a good practice.

This is my first real interaction with activiti, all this info is based on previous spring experience
(and the fact that I tried and it worked  Smiley Happy )

gergelydombi
Champ in-the-making
Champ in-the-making
I have to admit that so far I really like the job you guys have all done with activiti, the designer and the spring integration. It is a great tooling for a developer with a Spring background. It took only a business day to
set up everything (using MS SQL Server) and integrate to our Spring environment.

Well done!

jbarrez
Star Contributor
Star Contributor
Great to hear, ant thanks! Such posts really motivate us 🙂

giga_zhang
Champ in-the-making
Champ in-the-making
My understanding is that if you use default autowiring then this problem should never occur.
Only when I switched to autowire byType I saw this problem. My suggested solution keeps the activiti
autowiring strategy as is, and enables the client to use another autowiring strategy (or keep the default).

So probably that is a good practice.

This is my first real interaction with activiti, all this info is based on previous spring experience
(and the fact that I tried and it worked  Smiley Happy )


Smiley Very Happy mustn't set the autowiring strategy.No matter what strategy you set, the exception will ben thrown