Announcement Announcement Module
No announcement yet.
System Properties Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • System Properties


    I am tearing my hair out trying to get this working:

    I have a java system property called a.b.c=c:/mydatafile.dat

    Now, I have a Spring bean called read file that has a String constructor argument that takes the absolute file name as an argument, ie:

    class MySpringBean {

    public class MyStringBean(String absoluteFileName) {
    new FileSystemResource(absoluteFileName);


    Now, in my XML config, I am trying to do this:

    <bean id="mySpringBean" class="MySpringBean">

    and it is failing as it tries to load a properties file, rather than resolving the
    system property!!!

    How on earth do you do this??? I am stumped!!!

  • #2
    Dont forget to configure a PropertyPlaceholderConfigurer.

    <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    Check the User Guide and look at the JavaDoc.

    If you are still stuck, post full configuration, program output etc.


    • #3
      Property Configurator

      PropertyPlaceholder only seems to resolve system properties if using it as a way to refer to a properties file, at least these are the only examples I have seen.

      My full config is above.....


      • #4
        You could use Spring Expression Language.

        This example from the reference manual:
        <bean id="taxCalculator" class="org.spring.samples.TaxCalculator">
            <property name="defaultLocale" value="#{ systemProperties['user.region'] }"/>
            <!-- other properties -->

        There's the link to the manual.


        • #5
          If my suggestion does not work for you there must be something else going on as it works for me?? I assume you tried the suggestion before dismissing it?


          • #6
            What error do you actually get? are you running this code from within an application/web server?

            On some older app servers you can use a system property to refer to a properties file anywhere on the disk. However more recently, I found that on some app servers (oracle 11gr2) it won't let you read the file, unless it is a servlet context resource. It seems to be a permissions issue.


            • #7
              PropertyPlaceholderConfigurer should have worked. Try setting the systemPropertiesMode to "SYSTEM_PROPERTIES_MODE_OVERRIDE". (Check the API for PropertyPlaceholderConfigurer).

              Let us know the actual error you see.