Environment variables in JBoss datasource

2019-02-20 06:28发布

I have a JBoss server running and want to deploy a service. The service connects to a database which is configured in the following xml file

<?xml version="1.0" encoding="UTF-8"?>
<datasources xmlns="http://www.jboss.org/ironjacamar/schema">
    <datasource jta="false" jndi-name="java:/PMBootStrapDS"
        pool-name="PMBootStrapDS" enabled="true" use-ccm="false">
        <connection-url>jdbc:postgresql://localhost:5432/i2b2</connection-url>
        <driver-class>org.postgresql.Driver</driver-class>
        <driver>postgresql-9.2-1002.jdbc4.jar</driver>
        <security>
            <user-name>i2b2pm</user-name>
            <password>demouser</password>
        </security>
        <validation>
            <validate-on-match>false</validate-on-match>
            <background-validation>false</background-validation>
        </validation>
        <statement>
            <share-prepared-statements>false</share-prepared-statements>
        </statement>
    </datasource>
</datasources>

To deploy it on different systems easily, I want to bind the database location to an environment variable. I tried something like this

<connection-url>jdbc:postgresql://${env.MY_DB_LOCATION}/i2b2</connection-url>

but it doesn't work.

Any suggestions on how to solve this issue?

1条回答
手持菜刀,她持情操
2楼-- · 2019-02-20 07:24

Make sure you have property substitution enabled in your standalone.xml.

Look for the following subsytem in standalone.xml, and make sure the values are set to true

<subsystem xmlns="urn:jboss:domain:ee:1.1">
     <spec-descriptor-property-replacement>true</spec-descriptor-property-replacement>
     <jboss-descriptor-property-replacement>true</jboss-descriptor-property-replacement>
</subsystem>

EDIT: This is only supported for eap6 and jboss 7.1.2 (or later)

查看更多
登录 后发表回答