Results 1 to 3 of 3

Thread: How do I access ${user.home} in JavaConfig?

  1. #1
    Join Date
    Oct 2008
    Location
    Cambridge, MA
    Posts
    56

    Default How do I access ${user.home} in JavaConfig?

    Hello All,

    How can I access ${user.home} using JavaConfig? I'd like to be able declare:
    Code:
    @PropertiesValueSource(locations="file:${user.home}/.isg/test.properties")
    as I do in the XML config presently:
    Code:
    <context:property-placeholder location="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.

    In XML config, I'd use:
    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>
    In JavaConfig, I'm trying to do:

    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();
    	
    }
    Thanks,
    Steven

  2. #2
    Join Date
    Apr 2007
    Posts
    307

    Default

    Hi Steven,

    This is not yet supported, but should be. Please enter a JIRA issue for this so we can track it.

    - C
    Chris Beams
    Spring Framework committer, VMware
    http://github.com/cbeams

  3. #3
    Join Date
    Oct 2008
    Location
    Cambridge, MA
    Posts
    56

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •