简体   繁体   中英

Parameterize import resource in spring bean file

I have a datasource.xml as following. I have two sql bean files for mySql and Oracle as some queries are dependent on the database, as for limit in mysql equivalent to rownum in oracle.I import the resource files from either oracle folder or mysql folder. For now, I have to go and change import statement before build. Is there any alternative like to have the database name in a property file.PropertyConfigurer does not work with import statement at least for Spring 3.0.5.

<import resource="classpath:oracle/SqlBeans.xml" />

<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
    <property name="jndiName" >
        <value>${ds-jndi}</value>
    </property> 
    <property name="lookupOnStartup" value="false" />
    <property name="cache" value="true" />
    <property name="proxyInterface" value="javax.sql.DataSource" />
</bean>

 <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
  <property name="dataSource" ref="dataSource" />
 </bean>

Spring profiles, mentioned by @RC, is a good idea but requires 3.1 I think.

This might be simpler:

<context:property-placeholder location="classpath:db-${my.env}.properties"/>

And set my.env on the java command line.

See this .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM