Hello All,
How can I access ${user.home} using JavaConfig? I'd like to be able declare:as I do in the XML config presently:Code:@PropertiesValueSource(locations="file:${user.home}/.isg/test.properties")
We store all machine-specific data, such as JDBC info, in a properties file the user's home directory. We then merge the properties file into the spring config using the PropertyPlaceholderConfigurer.Code:<context:property-placeholder location="file:${user.home}/.isg/test.properties" />
In XML config, I'd use:
In JavaConfig, I'm trying to do:Code:<?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:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd"> <context:property-placeholder location="file:${user.home}/.isg/test.properties" /> <!-- put to separate object to allow for retrieval by performance tests. --> <bean id="bdbHome" class="java.lang.String"> <constructor-arg index="0" value="file:/${user.home}/db/" /> </bean> <!-- put to separate object to allow for retrieval by performance tests. --> <bean id="bdbdir" class="java.io.File"> <constructor-arg index="0" value="${user.home}/db/" /> </bean> <context:annotation-config /> </beans>
Thanks,Code:@PropertiesValueSource(locations="file:${user.home}/.isg/test.properties") @Configuration(checkRequired=true) public abstract class ApplicationConfig { @Bean() public StartupConfig getConfig() { StartupConfig startup = new StartupConfig(); startup.setDatabaseHomeDirectory(new File(getBDBDir())); return startup; } @Bean public BDBWrapper getWrapper() throws DatabaseException { return new BDBWrapper(getConfig()); } @ExternalValue(value="indivo.bdbhome") public abstract String getBDBDir(); }
Steven


