Reputation: 1091
I have trouble getting @Value annotations working with a Spring bean in a Grails 2.3.4 app.
I have a separate jar as a Grails dependency. The jar has annotated beans:
@Named
public class Bean {
@Value("${client.environment}")
private String environment;
....
}
I have setup the property in Config.groovy.
...
client.environment = "DEV"
...
When I run Grails in IntelliJ IDEA the property works and the @Value annotated variable is populated automatically. But when I deploy the war to a standalone Jetty instance the same property has not been initialized and its value is instead "${client.environment}".
I have tried for hours to check all production and development settings so they don't change anything. I've also tried multiple solutions to load properties in Grails and even tried to setup a propertyPlaceholderConfigurer in resources.groovy but nothing helps.
Upvotes: 3
Views: 3186
Reputation: 157
The @Value annotation from Spring needs single quotes in order to work (Tested on Grails 4):
import org.springframework.beans.factory.annotation.Value;
public class Bean {
@Value('${client.environment}')
String environment;
...
}
Upvotes: 2
Reputation: 1091
So I got the bean working as inteded by following these instructions. First I read the property from the property file and explicitly set it to the bean variable using the last method in the following URL (using beans in Config.groovy)
http://softnoise.wordpress.com/2013/07/29/grails-injecting-config-parameters/
Upvotes: 1