user1987876
user1987876

Reputation: 29

REQ: Retrieving properties in my java app. collected by "PropertyPlaceholderConfigurer" -- properties are stored in a database as key/value

PUsing Spring 3.2.0.release and JDK 1.6. I've a standalone Java program (NOT running inside tomcat etal) and I'm loading properties from a database.

I've used this excellent article as a base and it works perfectly. Using the PropertiesPrinter bean (defined there) as a base and adding getters I can do stuff like getFileLocation(), getPetDogsName() but then I need to have/create setter/getters for every property.

What I would like to have is a Spring Bean or normal Java class called DatabaseProperties with a method like getProperty("filelocation"); which I can use in my application (main)and so I can retrieve/get the value of the property filelocation which is somewhere inside the information collected by PropertyPlaceholderConfigurer.

I've done a lot of digging but can't seem to find the information I need or at least I'm not able to combine the gathered info into a working program as I'm not fluent with Spring....

Any hint/pointers/urls/code is higly appreciated. It's probably relative easy but it is still out of reach for me atm.

Upvotes: 0

Views: 117

Answers (1)

Reimeus
Reimeus

Reputation: 159794

One solution for reading values set by the PropertyPlaceholderConfigurer, is to use the @Value annotation rather than a method for setting class member variables:

class MyClass {

   @Value("${file.location}")
   private String fileLocation;
   ...
}

Upvotes: 1

Related Questions