Reputation: 1038
I have Camunda 7.10 running on Tomcat 9.0.12.
The process engine datasource is configured in
/[tomcat-home]/conf/server.xml
and, by necessity, is available to all deployed web-apps.
I wish to configure a process specific datasource that is only available to that process.
For a normal web app, there is typically a
[tomcat-home]/webapps/[web-app-name]/META-INF/context.xml
configuration file that defines the datasource and the locator code that returns a javax.sql.DataSource
using a javax.naming.InitialContext
etc
Looking at the deployment of the specific process, there are two META-INF folders
[tomcat-home]\webapps\[process-name]\META-INF
[tomcat-home]\webapps\[process-name]\WEB-INF\classes\META-INF
The first has maven specific items. The second is where the process.xml file resides.
Using proven datasource locator code and putting a proven context.xml
file here fails with
javax.naming.NameNotFoundException: Name [jdbc/recruitDS] is not bound in this Context. Unable to find [jdbc].
Searching for this only leads to information on the main Camunda process engine datasource configuration which is well covered in the manual, forums etc.
Upvotes: 0
Views: 969
Reputation: 1038
The following configuration works for Camunda 7.10 running on Tomcat 9.0.12 accessing SQL Server 2012 using a Maven build project as per the Camunda Java Process Get-Started example.
In the exploded WAR file, in the folder:
[tomcat-home]\webapps\[process-name]\META-INF
there must be a context.xml file with these fields:
<?xml version="1.0" encoding="UTF-8"?>
<Context>
<Resource
name="jdbc/myDatasource"
global="jdbc/myDatasource"
auth="Container"
type="javax.sql.DataSource"
driverClassName="com.microsoft.sqlserver.jdbc.SQLServerDriver"
url="jdbc:sqlserver://127.0.0.1:1433;databaseName=myDatabaseName"
username="myUsername"
password="myPassword"
maxTotal="50"
maxIdle="0"
maxWaitMillis="-1"
removeAbandonedOnBorrow="true"
removeAbandonedOnMaintenance="true" />
</Context>
The important field is the global
tag - missing this causes the above exception. For a normal JSP/servlet web-app, this field is not necessary as the scope is limited to that web-app. For Camunda, the task listeners etc run in the scope of the main Camunda web-app.
Using a Maven build, it is just a case of adding the META-INF
folder & file to the project file structure.
Then, in a Camunda JavaDelegate
or TaskListener
, it is possible to use the DataSource
to obtain a connection in the usual manner via an InitialContext
with a URL of the form:
java:/comp/env/jdbc/myDatasource
Using a process specific data-source avoids polluting the main tomcat server.xml
configuration file with process specific items.
Upvotes: 1