Reputation: 1741
I am developing a web application using EJB in TomEE.
To separate development, test, and production environments of the application, I use different <Host>
entries in server.xml
. So the environments can be chosen by different URLs, like dev.myapp.example.tld
and test.myapp.example.tld
.
The resources (at this moment database connections) are defined in tomee.xml
as
<Resource id="myappDatabaseDevelopment" type="DataSource"> ...
<Resource id="myappDatabaseTest" type="DataSource"> ...
Now, the app in the test host shall access the test database, same for dev host and dev database. But that's a clumsy solution, as the two resources have different id
s, so I have to decide in the Java code, depending on the environment it's running in, which persistence unit to choose. It would be preferable to manage this by container configuration. But I can't find any way to specify in the TomEE config files which resource is to be used in which host. server.xml
has hosts, tomee.xml
has resources, but no way to reference one from the other.
Somehow, TomEE appears to recognize the different hosts, however. When I deploy the two versions of the same app under the same host, but different app (context) names, I get errors because of duplicate deployment ids, plus lots of trouble because of mixing container managed beans between the two apps. Using different hosts (and different appBase
s) makes those errors go away.
Is there any way to have multiple configurations of a resource, having the same id
, depending on the host?
Upvotes: 0
Views: 251
Reputation: 3422
have a look to https://issues.apache.org/jira/browse/TOMEE-1449, adding host in the deployment id should be enough.
Upvotes: 2