Announcement Announcement Module

JavaConfig forum decommissioned in favor of Core Container

As described at

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:

For any questions related to @Configuration classes and @Bean methods in Spring 3.0, please post in the dedicated 'Core Container' forum at
See more
See less
Is there really no equivalent to the 'placeholder' notation used in XML files? Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Is there really no equivalent to the 'placeholder' notation used in XML files?


    My application uses a system environment variable, populated at JVM startup, to ascertain which environment the application is running in e.g. dev, UAT, pre-prod, prod etc.

    We then plug that variable into various Spring imports to initialise the IOC container with a series of XML files pertaining to the correct environment e.g.

    <import resource="classpath:com/my/application/some-component-${environment}.xml"/>

    ....might resolve to...

    com/my/application/some-component-prod.xml production. We are keen to begin using JavaConfig to reduce our inordinate number of XML configuration files, which largely contain duplicative data that might only differ for one environment (usually production). However, we'll still need some property files to hold per-environment, non-default values.

    And for the life of me, I can't see how it's done with Spring JavaConfig!!! In both these cases...

    @PropertiesValueSource(locations = { "classpath:com/my/application/some-component-${environment}.properties" })


    private @ExternalValue("${environment}.port.number") int portNumber = 1234;

    ...the ${environment} is ignored. Similarly, an approach like....

    private @ExternalValue(System.getProperty("environment") + ".port.number") int portNumber;

    ...arises a compiler error, because annotation values must be compile-time constants, as opposed to run-time ones.

    So, is there really no way in Spring Java Config 1.0.0 M4 to achieve what has always been relatively simple with XML Configuration files? If not, I find it very disappointing.

    As always, any advice would be much appreciated (and lastly, bear in mind that we're not in a position to upgrade from Spring 2.5 to Spring 3),