user184794
user184794

Reputation: 1036

Access message.properties in Java Class

I have a message.properties file like:

message1=value1
message2=value2
...

I am using Spring 3. I would like to know how I can access the values of messages (value1, value2...)in a Java class. (something like props.getProperty("message1")). I understand we can use util:properties... or PropertyPlaceholderConfigurer. But in both ways, how we can access in Java class after configuration in XML file?

It would be great if you could guide me all the steps (in xml and java)c or any example.

Upvotes: 0

Views: 1415

Answers (1)

fpmoles
fpmoles

Reputation: 1219

Inject the util:properties bean into your class

//Constructor
public Foo(Properties props){
    super();
    this.props = props;
}

Then in your spring config do the following

<bean id ...>
     <constructor-arg ref="propsBean" />
</bean>
<util:properties id = "propsBean" location = "...." />

Upvotes: 1

Related Questions