12

I already know how to:

Load properties files into my Spring configuration using:

<context:property-placeholder location="aaa/bbb/ccc/stuff.properties"/> 

Build properties objects on the fly using:

<props><prop key="abc">some value</prop></props>

But what I cant do, and would be really useful, is to have Spring load a properties file and then build the matching properties object. I could then inject this into a bean in the normal way.

I've searched for this elsewhere without success. Any ideas?

Chris
  • 6,761
  • 6
  • 52
  • 67
Garth Gilmour
  • 11,124
  • 5
  • 25
  • 35

1 Answers1

17

Take a look at util:properties

<util:properties id="myProperties" location="classpath:com/foo/my.properties"/>

Then, to inject the Properties into your Spring-managed Bean, it's as simple as this:

@Resource(name = "myProperties")
private Properties myProperties;
Tom
  • 16,842
  • 17
  • 45
  • 54
toolkit
  • 49,809
  • 17
  • 109
  • 135