04-28-2012 04:41 PM
public class SpringServiceTask implements JavaDelegate {
private DataSource ds;
public void setDataSource(DataSource ds) {
this.ds= ds;
}
public void execute(DelegateExecution execution) throws Exception {
System.out.println("DataSource "+ds); // NULL!
}
}
However the injection does not happens and this the execute method prints null.<bean id="reviewApproved" class="com.sample.ReviewApproved">
<property name="ds" ref="dataSource"/>
</bean>
Any help ?05-02-2012 03:51 AM
04-29-2012 11:00 AM
04-29-2012 11:44 AM
<bean id="springServiceTask" class="com.sample.SpringServiceTask">
<property name="ds" ref="dataSource"/>
</bean>
(sorry in the original message I've cut and paste another Service task declaration)04-30-2012 04:31 AM
04-30-2012 10:47 AM
How do you try to activate the bean? can you the code that call the bean?Hello,
From the look of it the spring definition seems OK
Make sure the datasource is defined correctly
<serviceTask id="servicetask1" name="Service Task" activiti:class="com.sample.MyServiceTask"></serviceTask>This is the Service Task implementation:
public class MyServiceTask implements JavaDelegate {
private DataSource dataSource;
public void setDataSource(DataSource dataSource) {
this.dataSource = dataSource;
}
public void execute(DelegateExecution execution) throws Exception {
System.out.println("Datasource is "+dataSource); // NULL!!
}
}
For example, here I'm using a Datasource which is injected using setter field injection. However it prints out null. (Same for other beans defined into applicationContext.xml) <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost:3306/activiti?autoReconnect=true" />
<property name="username" value="activiti" />
<property name="password" value="activiti" />
<property name="defaultAutoCommit" value="false" />
</bean>
Last thing: I'm trying to execute this process from within the process-explorer application, so I'm using the applicationContext.xml inside it.05-02-2012 03:51 AM
05-02-2012 04:31 AM
Hi,Ah, got it, sorry. In other words not hardwiring a Java class into the Service Task, but using an expression that resolves to a Spring Bean. Thanks!
Like Ronald already said in an earlier post. To inject Spring beans in a service task class, the service task class also must be a Spring bean.
So you have to configure a service task with an expression that points to a Spring bean. In the Spring config you can then inject the datasource property into the Spring bean.
You can find an example in the userguide.
Best regards,
01-19-2017 05:10 AM
Can you please tell how you have achieved this.I'm also using the same
05-02-2012 07:39 AM
Ah, got it, sorry. In other words not hardwiring a Java class into the Service Task, but using an expression that resolves to a Spring Bean. Thanks!
Frank
Tags
Find what you came for
We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.