cancel
Showing results for 
Search instead for 
Did you mean: 

JNDI datasource configuration

kjozsa
Champ in-the-making
Champ in-the-making
I am installing Activiti 5.17.0 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 the docs seems to be obsolete.

In particular, I found no activiti-standalone-context.xml and no activiti-context.xml. 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 various Spring methods (<jee:jndi-lookup> or the JndiObjectFactoryBean way shown in the Activiti docs, playing around with the expected-type option, etc., but all my attempts ended up in a ClassCastException, claiming that the generated Proxy class is not an instance of javax.sql.DataSource.

Any hints how to accomplish to this task? Maybe a pointer to an up-to-date documentation? Thanks a lot in advance!
7 REPLIES 7

trademak
Star Contributor
Star Contributor
Hi,

You are trying to get this working with the Activiti Explorer or Rest web application I assume?
Yes, the activiti-custom-context.xml is the right place to change this. It's in comments, because it just shows an example of how it could be used, by default there's no custom Spring context needed. Can you share your xml definition?

Best regards,

kjozsa
Champ in-the-making
Champ in-the-making
Hi Tijs,

I tried this approach:
<code>
<jee:jndi-lookup id="dataSource"
           jndi-name="jdbc/activiti-ds"
           expected-type="javax.sql.DataSource" />
</code>
as well as this one:
<code>
<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>
</code>
but both of them ended up with the same error both in Tomcat and Weblogic 12c, claiming that:
<code>
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)
</code>

I managed to come around the issue making the configuration via JavaConfig but if there's an XML approach which could work, I would highly prefer that. Thanks a lot!

jbarrez
Star Contributor
Star Contributor
The only other option i know of is using the JndiDataSourceLookup class. But I've only used it in java config way, not xml.

aggiepilot04
Champ in-the-making
Champ in-the-making
The following works for us on Activiti 5.14 and Weblogic 10.3.6:

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

Make sure you have the reference in your processEngineConfiguration:

<code>
    <bean id="processEngineConfiguration" class="org.activiti.spring.SpringProcessEngineConfiguration">
  <property name="dataSource" ref="dataSource" />

</code>

And lastly, make sure you delete (or leave commented) the other definition for dataSource:

<code>
    <bean id="dbProperties" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
     <property name="locations">
            <list>
                <value>classpath:db.properties</value>
                <value>file:activiti-rest.properties</value>
            </list>
        </property>
  <property name="ignoreUnresolvablePlaceholders" value="true" />
  <property name="ignoreResourceNotFound" value="true" />
</bean>

<bean id="dataSource"
  class="org.springframework.jdbc.datasource.SimpleDriverDataSource">
  <property name="driverClass" value="${jdbc.driver}" />
  <property name="url" value="${jdbc.url}" />
  <property name="username" value="${jdbc.username}" />
  <property name="password" value="${jdbc.password}" />
</bean>
</code>

Oh, and make sure you've copied the appropriate driver jar into WEB-INF/lib.

I have also confirmed that this works with Activiti 6/Tomcat7/Oracle DB.  Well, it works with activiti-rest…context.xml is not in play in activiti-app.  Here's how it looks in activiti-app.properties:

datasource.jndi.name=jdbc/activiti
datasource.driver=oracle.jdbc.driver.OracleDriver
hibernate.dialect=org.hibernate.dialect.Oracle10gDialect

transaction manager configuration is not necesary?

<bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager"  />

http://docs.spring.io/spring/docs/current/spring-framework-reference/html/transaction.html

jbarrez
Star Contributor
Star Contributor
@aggiepilot04 : thanks for posting this. I'm sure many people will find this helpful!

geekonspace
Star Contributor
Star Contributor
This is my configuration:

<jee:jndi-lookup id="dataSource" jndi-name="JDBC/ORION" expected-type="java.sql.DataSource" />

<bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager"/>

<bean id="processEngineConfiguration" class="org.activiti.spring.SpringProcessEngineConfiguration">
    <property name="dataSource" ref="dataSource" />
    <property name="databaseSchemaUpdate" value="true" />
    <property name="jobExecutorActivate" value="false" />
    <property name="transactionManager" ref="transactionManager"></property>
  </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" />

transactionManager is not   necesary? <bean id="txManager" class="org.springframework.transaction.jta.JtaTransactionManager"/>