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