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
Is there really no equivalent to the 'placeholder' notation used in XML files? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

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

    Hi,

    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


    ....in 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" })

    ...and....

    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),

    Cheers,
    Al
Working...
X