gotch4
gotch4

Reputation: 13259

Dynamic list properties in spring

I've been googling this for about a hour, with little success.

Suppose that in my web.xml I have :

<Parameter name="hibernate.websitespecific.entityscanpackages" value="com.mystuff.pojo.entities, com.mystuff.otherpackage.pojo.entities"/>

and in my spring context config I have:

 <bean id="sessionFactory"
          class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
        <property name="packagesToScan">
            <list>
                <value>com.mystuff.somethingelse.pojo</value>
                <value>com.mystuff.weirdbeans.domain</value>
            </list>
        </property>
[...]

I'd like to add hibernate.websitespecific.entityscanpackages to the list of packages to scan in a clean way. How do I do that?

Upvotes: 0

Views: 242

Answers (1)

Jose Luis Martin
Jose Luis Martin

Reputation: 10709

You can reference context parameters in bean definition files using SPEL:

For example:

<property name="foo" value="#{contextParameters.fooParamName}" />

Edit

To merge the both package list:

<property name="packagesToScan" value="#{contextParameters.paramName + ',pk1,pk2,pk3'}"/>

or

<property name="packagesToScan" value="#{contextParameters.paramName + ',' + T(org.springframework.util.StringUtils).collectionToCommaDelimitedString(@someList)}" />

    <util:list id="someList">
      <value>pk1</value>
      <value>pk2</value>
     ...
    </util:list>

Upvotes: 1

Related Questions