Yevgen Nerush
Yevgen Nerush

Reputation: 91

Default placeholder value in spring xml

In our specific application db.properties file is provided by 3d party. Dependent on configuration, this property file could contain db.schema property or not. So, if there is no db.schema property, the db.username must be used for hibernate.default_schema property.

The placeholder ${db.schema:db.username} does not retrieve value of db.username if db.schema does not exist, so that 'db.schema' value is propagated instead of actual (i.e. dba) one.

So, the question is: how to propagate default value of db.username if db.schema does not exist (lets assume that db.username always exists) ?

<util:properties id="specificHibernateProperties">
    <prop key="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</prop>
    <prop key="hibernate.show_sql">true</prop>
    <prop key="hibernate.hbm2ddl.auto">update</prop>
    <prop key="hibernate.default_schema">${db.schema:db.username}</prop>
</util:properties>

Upvotes: 4

Views: 1710

Answers (1)

Shake
Shake

Reputation: 61

In Spring 3, it should be possible to use nested placeholders. So please try this:

${db.schema:${db.username}}

/rgrds

Upvotes: 6

Related Questions