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

  • System properties and PropertyPlaceholderConfigurer

    I've been playing around with Spring+Hibernate with an hsqldb database. If you want to run hsqld standalone, you need to specify the URL in the form:

    jdbc:hsqldb:file:/full/path/to/database/directory

    As this is obviously not something I'd want to 'hard code', I thought I'd try to use a path relative to the home directory, as contained in the system property 'user.dir'. So, in the datasource section of my applicationContext.xml, I tried the following:

    <property name="url">
    <value>jdbc:hsqldb:file:${user.dir}/WEB-INF/db/db</value>
    </property>

    Unfortunately, when I tried to use this URL, it showed up without any replacement, i.e., as:

    jdbc:hsqldb:file:${user.dir}/WEB-INF/db/db</value

    Is there something else I have to do?

  • #2
    PropertyPlaceholderConfigurer does not support System Properties. You can however "hard code" the path inside a jdbc.properties file.

    Comment


    • #3
      Originally posted by irbouho
      PropertyPlaceholderConfigurer does not support System Properties. You can however "hard code" the path inside a jdbc.properties file.
      According to the Javadoc for PropertyPlaceholderConfigurer:

      'A configurer will also check against system properties (e.g. "user.dir") if it cannot resolve a placeholder with any of the specified properties. This can be customized via "systemPropertiesMode".'

      Theer's no explanation of how this customizing is done, but I tried this:

      <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.Pr opertyPlaceholderConfigurer">
      <property name="systemPropertiesMode">
      <value>SYSTEM_PROPERTIES_MODE_OVERRIDE</value>
      </property>
      </bean>

      Unfortunately this just gave me the following:

      org.springframework.beans.TypeMismatchException: Failed to convert property value of type [java.lang.String] to required type [int] for property 'systemPropertiesMode'; nested exception is java.lang.NumberFormatException: For input string: "SYSTEM_PROPERTIES_MODE_OVERRIDE"

      I may have to fall back to the jdbc.properties approach, although I would like to make this really dynamic.

      Comment


      • #4
        I believe I have solved the problem myself, by the addition of the following to the applicationContext.xml:

        <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.Pr opertyPlaceholderConfigurer"/>

        I had wrongly believed that there was a default configurer.

        Comment


        • #5
          Very strange, I had posted a reply in here that PropertyPlaceholderConfigurer does support use of System properties, but it seems to have vanished.

          The System properties can be considered either before or afte the ones coming from the Properties file.

          Comment


          • #6
            I think it does support the use of system properties. I don't believe that was my problem.

            Comment

            Working...
            X