I have situation in my application.
I have Property file called application.property and that one has some contains.
I want to change that contains at application startup, becore spring load.
I have to call server to get the latest values which I am going to use in my project.
so I have to change that onw before spring load so that I can use that one in my application.
Please guide me on this.
I have some idea that we can use PropertyPlaceholderConfigurer or PropertyOverrideConfigurer, but dont know how.
I have situation in my application.
I have Property file called application.property and that one has some contains.
I want to change that contains at application startup, becore spring load.
I have to call server to get the latest values which I am going to use in my project.
so I have to change that onw before spring load so that I can use that one in my application.
Please guide me on this.
I have some idea that we can use PropertyPlaceholderConfigurer or PropertyOverrideConfigurer, but dont know how.
The PropertyPlaceholderConfigurer will read the .properties file and make them accessible in your configuration via ${}
so if you have a database.properties with say
database.url=my.url.com
Then in your Spring config file you declare a bean for the Configurer
I'd probably look into the property placeholder code and see how it does its variable substitution--just do the same thing, but getting the values from the other location instead of the properties file. My guess is that it shouldn't be that difficult.
David Newton wrote:I'd probably look into the property placeholder code and see how it does its variable substitution--just do the same thing, but getting the values from the other location instead of the properties file. My guess is that it shouldn't be that difficult.
Other possibilities are
creating a FactoryBean class
implementing an init-method
create a BeanFactoryPostProcessor
create a PropertyEditor if using Spring 3.0 create a Converter
Mark
Ravi Pandya
Greenhorn
Joined: Jun 07, 2007
Posts: 21
posted
0
Hi.
thing is like this.
I have a property file which contains some properties.
At the Application startup I have to refresh this property file with some new properties.
and then I amd going to use that properties in to Application.
I am using Spring framework so I have to have something which refresh these properties with new values before spring loads.
So you want to change the .properties file at Spring startup, meaning as Spring is starting up, it will update that file. Then later you will use that file to set properties in other classes.
So where does it figure out the new values, and why even need a .properties file if it is only used at Spring startup, and the Spring startup already then knows about the values. Why not then just use those values immediately instead of putting it into a properties file.
I think you might need to rethink your design.
What is the use case, and whys?
Mark
Ravi Pandya
Greenhorn
Joined: Jun 07, 2007
Posts: 21
posted
0
Hi Mark.
Actually the flow is something like this.
I am taking some property values from property file and using those values, I am calling one server to get some more configuration values.
so for this thing I need property file for initial values and I am using spring so I need after that also.
This is a good way in my side because if I want to change something or anyone want to change something then we dont need to do that in property file. we just need to change in remote configuration server and restart the application, application will automatically take the new values at the startup and used those ones in application.
If you still feel that there is some other way to do this then please let me know.
Well, the purpose of a separate properties file is for that exact reason, you just change the properties file manually and restart the deployment. So now you are trying to go even further to externalize your externalized property file, but further externalizing the property file properties with another property file.
Aren't you going a little overboard here. Your location of the file can be "classpath:", "http:", or "file:"
Why not just use file so that the properties file is outside any .war and resides on the server.
I really think you are trying to over-complicate this.
Good Luck
Mark
Ravi Pandya
Greenhorn
Joined: Jun 07, 2007
Posts: 21
posted
0
Hi Mark.
You are right, but this is requirement of our project.
I already gave you a solution that would handle this--why didn't you take it?
chitti mars
Greenhorn
Joined: Oct 23, 2011
Posts: 3
posted
0
I have similar requirement, i have a db params in properties file.. at startup i need to encrypt the sensitive data and overwrite the properties file (with encrypted values). and while getting the db connection i need to decrypt internally and use for connection. Any suggestions please.