Spring String Concatenated Property Stores

My problem looks simple, but I cannot solve it. I have a properties file that contains configuration information for all environments (dev, qa, prod).

An example config.properties:

dev.maxLength=2000  
qa.maxLength=4000

We have a parent properties file that contains the host name, environment mappings.

An example hosts.properties:

host1=dev
host2=qa

The name of the property host1is stored in the bean hostname.

<bean id="hostname"
  factory-bean="localhostInetAddress"
  factory-method="getHostName"/> 

To resolve the name of the configuration property, I need to join the strings as follows: ${${**hostname**}.maxLength}which should be resolved as${dev.maxLength}

I tried to use SpEL without success. I get an exception Could not resolve placeholder. How can I combine the bean value in a place holder? How are dynamic property names constructed?

Spring version 3.2

+5
source share
3

, PropertyPlaceholderConfigurer beans Properties. <util:properties/> SpEL.

: "#{prop[host+'.'+'maxLength']}"

host - bean.

+2

, Spring, , quoutes ('') - SpEL #{}.

<bean id="myService" class=""com.services.MyService">
  ...
  <property name="endpointAddress" value="#{'${server}' + ':' + '${port}' + '${endpoint}'}" />
</bean>

:

server = http://domain.host.com

port = 7777

endpoint =/services/myservice

:

http://domain.host.com:7777/services/myservice

+12

, , Spring. , xml db, local.db.xml, dev.db.xml, qa.db.xml prod.db.xml. db.xml .

local.db.xml

<beans profile="db.local" .. >

Tomcat

-Dspring.profiles.active=db.local 
+2
source

All Articles