Announcement Announcement Module
Collapse

JavaConfig forum decommissioned in favor of Core Container

As described at

http://static.springsource.org/sprin...fig/README.TXT

key features of the Spring JavaConfig project have been migrated into the core Spring Framework as of version 3.0.

Please see the Spring 3.0 documentation on @Configuration and @Bean support:

http://static.springsource.org/sprin...tml#beans-java

For any questions related to @Configuration classes and @Bean methods in Spring 3.0, please post in the dedicated 'Core Container' forum at

http://forum.springsource.org/forumdisplay.php?f=26
See more
See less
How do I access ${user.home} in JavaConfig? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    Hi Steven,

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

    - C

    Comment


    • #3
      Done

      http://jira.springframework.org/browse/SJC-221

      Comment

      Working...
      X