Using Application Properties with Spring 3

I’m new to Spring and it can be a lot to take in. I was confused by properties and Spring. Not Spring configuration properties, but properties that are used in the application. I just wanted global access to my application properties. I might run into issues further down, like if I want to dynamically update properties, but so far, this is what I have.

1. In my app-config.xml Spring config file:

    <bean id="appProperties" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
        <property name="location" value="" />

2. In the components that I wanted to use properties (some are annotated with @Service and others with @Component) I used the @Value notation. In addition, there were a few where I wanted to set a default in case the property was missing. In this situation the property is really there just in case something needs to be changed w/o redeploying.

public class RestClient {
	private Integer timeout = 360;
	private String fileContentType = HTTP.DEFAULT_CONTENT_TYPE;

	public void doSomething() {

The above worked to read in the property and the assignment was used if the property is missing.


Leave a Reply

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

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

Google+ photo

You are commenting using your Google+ 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