Note that there are some explanatory texts on larger screens.

plurals
  1. POIs it possible to read a combination of a System Property and a Customized Property in Spring config file?
    primarykey
    data
    text
    <p>I need to know if its possible in Spring to derive a value for a Property by combination of a System-Property and a Customized-Property defined over a PropertyFile.</p> <p><strong>What I've done:</strong></p> <p>1) Configured a -D argument in server as : -Dapp.Env="dev" <br> 2) In my spring-config.xml, defined datasource details as below:</p> <pre><code>&lt;!-- DataSource configurations --&gt; &lt;bean id="myDataSource" class="com.atomikos.jdbc.AtomikosDataSourceBean" init-method="init" destroy-method="close"&gt; &lt;property name="uniqueResourceName" value="myDataSource" /&gt; &lt;property name="xaDataSourceClassName" value="${my.database.xaDriver.class}" /&gt; &lt;property name="xaProperties"&gt; &lt;props&gt; &lt;prop key="URL"&gt;#{systemProperties['appEnv']}.${my.database.jdbcUrl}&lt;/prop&gt; &lt;prop key="user"&gt;#{systemProperties['appEnv']}.${my.database.user}&lt;/prop&gt; &lt;prop key="password"&gt;#{systemProperties['appEnv']}.${my.database.password}&lt;/prop&gt; &lt;/props&gt; &lt;/property&gt; &lt;property name="maxPoolSize" value="${my.database.maxPoolSize}" /&gt; &lt;property name="minPoolSize" value="${my.database.minPoolSize}" /&gt; &lt;property name="borrowConnectionTimeout" value="60" /&gt; &lt;property name="maintenanceInterval" value="120" /&gt; &lt;/bean&gt; </code></pre> <p>3) Defined the following properties in my .properties file: my.database.xaDriver.class=oracle.jdbc.xa.client.OracleXADataSource <br> my.database.initialPoolSize=2 <br> my.database.maxPoolSize=10 <br> my.database.minPoolSize=2 <br></p> <p>dev.my.database.jdbcUrl=jdbc:oracle:thin:@test.com:1535:myDb <br> dev.my.database.user=myuserid <br> dev.my.database.password=mypwd <br></p> <p>4) Defined .properties file location in the spring-config.xml as :</p> <pre><code>&lt;context:property-placeholder location="/WEB-INF/spring/spring-config.properties" /&gt; </code></pre> <p><strong>What I get on start of server :</strong></p> <p>Throwable occurred: org.springframework.beans.factory.BeanDefinitionStoreException: Invalid bean definition with name 'myDataSource' defined in ServletContext resource [/WEB-INF/spring/spring-config.xml]: Could not resolve placeholder 'my.database.jdbcUrl' in string value "#{systemProperties['appEnv']}.${my.database.jdbcUrl}"</p> <p><strong>What I also tried :</strong></p> <p>5) Defined a property in .properties file as below: <br> app.Env=dev</p> <p>6) Modified the datasource bean configuration as below:</p> <pre><code> &lt;prop key="URL"&gt;${app.Env}.${my.database.jdbcUrl}&lt;/prop&gt; &lt;prop key="user"&gt;${app.Env}.${my.database.user}&lt;/prop&gt; &lt;prop key="password"&gt;${app.Env}.${my.database.password}&lt;/prop&gt; </code></pre> <p>However on start of server, I get same exception message :</p> <p>Throwable occurred: org.springframework.beans.factory.BeanDefinitionStoreException: Invalid bean definition with name 'myDataSource' defined in ServletContext resource [/WEB-INF/spring/spring-config.xml]: Could not resolve placeholder 'my.database.jdbcUrl' in string value "${app.Env}.${my.database.jdbcUrl}"</p> <p>Can someone help me out in pointing out what mistake I might be doing and what is/are the possible fix for this issue ?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload