• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Rob Spoor
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Carey Brown
Bartenders:

Setting properties in my APP using Spring

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have been trying to use Spring as a configuration serve for my App. I have looked into using the PRopertyPlaceholder functionality. I would like to have settings for properties set inot individual classes, not the monolithic place where all the values for PropertyPlaceholder are put.

Any advice?
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Mi Ku wrote:I have been trying to use Spring as a configuration serve for my App. I have looked into using the PRopertyPlaceholder functionality. I would like to have settings for properties set inot individual classes, not the monolithic place where all the values for PropertyPlaceholder are put.

Any advice?



Use the util namespace and use <util:properties id="someName" location="somelocation.properiest"/> tag,

Now you have a bean that gets created of type Properties that you can inject into you classes.

Mark
 
Mi Ku
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks.

What if I do not want to use a properties file, just a setting for a property in a bean or a set op properties in a Singleton that I can use in many classes
 
author & internet detective
Posts: 41502
881
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Mi Ku wrote:Thanks.

What if I do not want to use a properties file, just a setting for a property in a bean or a set op properties in a Singleton that I can use in many classes


Then why use properties? If they are hard coded in the application, you could be using Java variables/constants.
 
author
Posts: 422
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Even then, you could use the Spring Expression Language to do almost anything you want. It works in either XML...



...or with the @Value annotation...



As for the "some expression", it could be something like "#{someOtherBean.someProperty}" to pull the value of some other bean property. Or it could be "#{systemProperties.SOME_SYSTEM_PROPERTY}" to pull from a system property. Or you could use "#{systemEnvironment['SOME_ENV_VARIABLE']}" to get it from an environment variable.

That only shows a tiny bit of what SpEL can do, but it seemed pertinent to the question posed here.
 
Mi Ku
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The value of the properties varies from environment to environment, hance the need to set them externally. Spring is the standard in my App. I am toying with the idea of creating a global properties file for all the settings and would like to have each individual developer 'pull' the value out of the properties file and inject them inot their beans as properties.

How would I "move" the values from the property file into each individual bean? I like the idea of the SPel, very much like the EL for JSPs

Thank you
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic