Spring @Value and resolving property names with dots

I’m moving a legacy application (I seem to be doing that a lot recently) to Spring and injecting properties with @Value into Spring managed beans all over the place. And it doesn’t work:

public class SomeService{
 @Value("#{the.org.namespace.someProperty}")
 private String someProperty;
}

Dots have apparently a special meaning, so this fails with a message that ‘the’ can’t be found:

EL1008E:(pos 0): Field or property 'the' cannot be found on object of type 'org.springframework.beans.factory.config.BeanExpressionContext'

They know about it [1], they said the fixed it [2] but up to now (3.2.4) they didn’t.

The solution is surprisingly simple: use $ instead of #

public class SomeService{
 @Value("${the.org.namespace.someProperty}")
 private String someProperty;

}

Resources

[1] http://forum.spring.io/forum/spring-projects/container/61648-spring-3m2-value-and-propertyplaceholderconfigurer

[2] https://jira.springsource.org/browse/SPR-5847

One thought on “Spring @Value and resolving property names with dots

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.