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

  • System Properties

    Hi,

    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">
    <constructor-arg><value>${a.b.c}</value></constructor-arg>
    </bean>

    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.

    Code:
    <context:property-placeholder/>
    or
    Code:
    <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.

    Comment


    • #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.....

      Comment


      • #4
        You could use Spring Expression Language.

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

        There's the link to the manual.

        Comment


        • #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?

          Comment


          • #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.

            Comment


            • #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.

              Comment

              Working...
              X