0

This isn't working:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:encryption="http://www.jasypt.org/schema/encryption"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
                        http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
                        http://www.jasypt.org/schema/encryption
                        http://www.jasypt.org/schema/encryption/jasypt-spring31-encryption-1.xsd">

    <import resource="properties/secure/jasypt-context.xml" />
    <bean name="propEnvironment" class="java.lang.String">
        <constructor-arg value="#{ systemProperties['property.environment'] ?: systemProperties['cfg.environment'] }" />
    </bean>
    <encryption:encryptable-property-placeholder 
        encryptor="configurationEncryptor"
        location="classpath:properties/#{propEnvironment}/*.properties,classpath:properties/common.properties" />

</beans>

Only common.properties gets configured by the encryptable property placeholder. It's like the other entry just disappears (no error is thrown or anything, it just doesn't load anything else). I want to stand up an instance with the production config files, but I want to use my dev properties. The spel expression is evaluating properly if I print that out. Is this possible?

When I try this,

<bean name="propEnvironment" class="java.lang.String" id="testing">
    <constructor-arg value="#{ systemProperties['property.environment'] ?: systemProperties['cfg.environment'] }" />
</bean>
<bean name="fullString" class="java.lang.String">
    <constructor-arg value="classpath:properties/#{ systemProperties['property.environment'] ?: systemProperties['cfg.environment'] }/*.properties" />
</bean>
<bean class="EchoBean" lazy-init="false">
    <constructor-arg ref="propEnvironment" />
</bean>
<bean class="EchoBean" lazy-init="false">
    <constructor-arg ref="fullString" />
</bean>
<bean class="EchoBean" lazy-init="false">
    <constructor-arg value="#{@testing.toString()}" />
</bean>
<bean class="EchoBean" lazy-init="false">
    <constructor-arg value="blah" />
</bean>

The third echo using the @ syntax does not produce any output.

2014-02-14 10:03:41,998 [main] INFO  EchoBean - local
2014-02-14 10:03:42,000 [main] INFO  EchoBean - classpath:properties/local/*.properties
2014-02-14 10:03:42,000 [main] INFO  EchoBean - blah
Cheese Daneish
  • 1,030
  • 7
  • 15

1 Answers1

0

Try this format:

<bean class="java.net.URI" id="dbUrl">
    <constructor-arg value="#{systemEnvironment['DATABASE_URL']}"/>
</bean>

<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
    <property name="url" value="#{ 'jdbc:postgresql://' + @dbUrl.getHost() + ':' + @dbUrl.getPort() + @dbUrl.getPath() }"/>
    <property name="username" value="#{ @dbUrl.getUserInfo().split(':')[0] }"/>
    <property name="password" value="#{ @dbUrl.getUserInfo().split(':')[1] }"/>
</bean>

What if you tried calling toString() on propEnvironment? Like so:

<encryption:encryptable-property-placeholder 
    encryptor="configurationEncryptor"
    location="classpath:properties/#{@propEnvironment.toString()}/*.properties,classpath:properties/common.properties" />
SergeyB
  • 9,478
  • 4
  • 33
  • 47
  • I don't know. It seems like Spring wants to build the property placeholder before it evaluates the spring-el – Cheese Daneish Feb 13 '14 at 23:12
  • @Mongo - posted an updated sample to try, hope it helps. If that doesn't work, can you try Autowiring 'propEnvironment' String bean into some Component and see if the value comes through correctly? – SergeyB Feb 13 '14 at 23:18
  • I updated the question at the bottom with the results of this. – Cheese Daneish Feb 14 '14 at 16:09