Activiti JNDI Datasource Configuration

2.4k views Asked by At

I am installing Activiti 5.17.0's Activiti Explorer and would like to use a JNDI-based datasource configuration to connect to an Oracle DB. The documentation I found here: http://www.activiti.org/userguide/#jndiDatasourceConfig is very explicit about making this change but unfortunately the docs seems to be obsolete.

In particular, I found no activiti-standalone-context.xml and no activiti-context.xml at the mentioned places. I assume it got changed to activiti-custom-context.xml, but the whole content of this Spring configuration is commented out (which makes me wonder where the actual Spring config might come from).

I tried to configure the datasource in this file anyway using this approach:

<jee:jndi-lookup id="dataSource"
           jndi-name="jdbc/activiti-ds"
           expected-type="javax.sql.DataSource" />

and this approach as well:

<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
           <property name="proxyInterface" value="javax.sql.DataSource"/>
           <property name="jndiName"><value>jdbc/activiti-ds</value></property>
</bean>

but both my attempts ended up in the same ClassCastException, claiming that the generated Proxy class is not an instance of javax.sql.DataSource:

java.lang.ClassCastException: org.springframework.jndi.JndiObjectFactoryBean$$EnhancerBySpringCGLIB$$69ba43af cannot be cast to javax.sql.DataSource
    at org.activiti.explorer.conf.ActivitiEngineConfiguration$$EnhancerBySpringCGLIB$$5db7207e.dataSource(<generated>)
    at org.activiti.explorer.conf.ActivitiEngineConfiguration.processEngineConfiguration(ActivitiEngineConfiguration.java:91)

Any hints how to accomplish to this task? Maybe a pointer to an up-to-date documentation?

2

There are 2 answers

0
Kristof Jozsa On BEST ANSWER

For further reference, I solved the problem by editing the Spring JavaConfig in ActivitiEngineConfiguration.java and replacing the dataSource bean creation there with the following code:

@Bean
public DataSource dataSource() {
    final JndiDataSourceLookup dsLookup = new JndiDataSourceLookup();
    dsLookup.setResourceRef(true);
    DataSource dataSource = dsLookup.getDataSource("jdbc/activiti-ds");
    return dataSource;
}

After recompiling the module and deploying, it seems to work flawlessly.

Thanks a lot to Greg Harley above whose questions and commented helped to solve the problem!

7
Greg Harley On

The Activiti users guide includes updated instructions for how to configure a JDBC datasource here: http://www.activiti.org/userguide/#jndiDatasourceConfig

You will need to configure a datasource bean in the ActivitiEngineConfiguration class of your web application and update the following line of code to reference your new datasource:

processEngineConfiguration.setDataSource(dataSource());

If you want to continue to use the Spring XML configuration, you can still define your custom beans in the activiti-custom-context.xml.