Announcement Announcement Module
Collapse
No announcement yet.
Spring XML doesn't allow property placeholders Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring XML doesn't allow property placeholders

    It appears that property placeholders don't work with the spring XML definitions. It would be nice to be able to support placeholders so all the things that may change between environments can be centrally loaded in properties, while the XML remains static.

    Works:
    Code:
        <gfe:partitioned-region id="Tagger"
            copies="2"
            recovery-delay="1000"
            persistent="true"
            disk-store-ref="Tagger.store"
            destroy="false"
            multicast-enabled="false"
            >
        </gfe:partitioned-region>

    Doesn't work:
    Code:
        <gfe:partitioned-region id="Tagger"
            copies="${replication}"
            recovery-delay="1000"
            persistent="true"
            disk-store-ref="Tagger.store"
            destroy="false"
            multicast-enabled="false"
            >
        </gfe:partitioned-region>
    The result is an exception at startup:
    ...
    Caused by: org.xml.sax.SAXParseException; lineNumber: 37; columnNumber: 4; cvc-datatype-valid.1.2.1: '${replication}' is not a valid value for 'integer'.
    at com.sun.org.apache.xerces.internal.util.ErrorHandl erWrapper.createSAXParseException(ErrorHandlerWrap per.java:198)
    at com.sun.org.apache.xerces.internal.util.ErrorHandl erWrapper.error(ErrorHandlerWrapper.java:134)
    at com.sun.org.apache.xerces.internal.impl.XMLErrorRe porter.reportError(XMLErrorReporter.java:437)
    at com.sun.org.apache.xerces.internal.impl.XMLErrorRe porter.reportError(XMLErrorReporter.java:368)
    at com.sun.org.apache.xerces.internal.impl.XMLErrorRe porter.reportError(XMLErrorReporter.java:325)
    at com.sun.org.apache.xerces.internal.impl.xs.XMLSche maValidator$XSIErrorReporter.reportError(XMLSchema Validator.java:453)
    at com.sun.org.apache.xerces.internal.impl.xs.XMLSche maValidator.reportSchemaError(XMLSchemaValidator.j ava:3232)
    at com.sun.org.apache.xerces.internal.impl.xs.XMLSche maValidator.processOneAttribute(XMLSchemaValidator .java:2827)
    at com.sun.org.apache.xerces.internal.impl.xs.XMLSche maValidator.processAttributes(XMLSchemaValidator.j ava:2764)
    at com.sun.org.apache.xerces.internal.impl.xs.XMLSche maValidator.handleStartElement(XMLSchemaValidator. java:2051)
    at com.sun.org.apache.xerces.internal.impl.xs.XMLSche maValidator.startElement(XMLSchemaValidator.java:7 41)
    at com.sun.org.apache.xerces.internal.impl.XMLNSDocum entScannerImpl.scanStartElement(XMLNSDocumentScann erImpl.java:376)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumen tFragmentScannerImpl$FragmentContentDriver.next(XM LDocumentFragmentScannerImpl.java:2717)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumen tScannerImpl.next(XMLDocumentScannerImpl.java:607)
    at com.sun.org.apache.xerces.internal.impl.XMLNSDocum entScannerImpl.next(XMLNSDocumentScannerImpl.java: 116)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumen tFragmentScannerImpl.scanDocument(XMLDocumentFragm entScannerImpl.java:489)
    at com.sun.org.apache.xerces.internal.parsers.XML11Co nfiguration.parse(XML11Configuration.java:835)
    at com.sun.org.apache.xerces.internal.parsers.XML11Co nfiguration.parse(XML11Configuration.java:764)
    at com.sun.org.apache.xerces.internal.parsers.XMLPars er.parse(XMLParser.java:123)
    at com.sun.org.apache.xerces.internal.parsers.DOMPars er.parse(DOMParser.java:237)
    at com.sun.org.apache.xerces.internal.jaxp.DocumentBu ilderImpl.parse(DocumentBuilderImpl.java:300)
    at org.springframework.beans.factory.xml.DefaultDocum entLoader.loadDocument(DefaultDocumentLoader.java: 75)
    at org.springframework.beans.factory.xml.XmlBeanDefin itionReader.doLoadBeanDefinitions(XmlBeanDefinitio nReader.java:388)
    ... 19 more




  • #2
    @svenz I have successfully reproduced this issue and will get back to you with further details and resolution.

    Comment


    • #3
      @svenz - Just to be clear Spring XML *does* support property placeholders. In this case, the XSD defines the attribute as an int, so the XML parser rejects the placeholder. It should be defined as a string. I have created an issue https://jira.springsource.org/browse/SGF-211 .You can watch it to track progress.

      Comment


      • #4
        Just keep in mind valid values are between 0 and 3

        Comment


        • #5
          This isn't the only instance I've run into. Most of the non-string types I've tried are either too tight in the schema, or fail to evaluate the placeholders before trying to convert to int.

          for example:
          <gfe-data:datasource>
          <gfe-data:locator host="${gemfire.client/locator:localhost}" port="10334" />
          </gfe-data:datasource>

          @port is schema defined as "string", but replace the "10334" with a placeholder and I get an exception that includes "java.lang.NumberFormatException: For input string: "${port:10334}"" in the cause, which I read as it didn't do the placeholder resolution before trying to type convert the value.

          Do you want me to add this to the bug, or as a different bug b/c its not the schema issue?

          Also seen for:
          partitioned-region/@recovery-delay
          partitioned-region/@multicast-enabled

          Comment


          • #6
            @dturanski Sorry, didn't mean to imply Spring in general not supporting placeholders. I was posting this in the Gemfire section because I know the issue is specific to the Gemfire Spring integration not supporting placeholders for all its fields.

            Comment


            • #7
              Oops... I stand corrected about datasource/locator/@port being a problem. I forgot to install the PropertyPlaceholderConfigurer in the client test application I built. The partitioned-region fields did have PropertyPlaceholderConfigurer installed.

              Comment


              • #8
                @svenz Thank you for the feedback. I just committed the fix for SGF-211 (https://jira.springsource.org/browse/SGF-211). Also in my testing, I verified the attributes...

                partitioned-region/@recovery-delay
                partitioned-region/@multicast-enabled

                Correctly accept placeholder values, and the do. For instance...

                Code:
                <util:properties id="partitionedRegionConfigurationSettings">
                  <prop key="destroy">false</prop>
                  <prop key="multicast-enabled">false</prop>
                  <prop key="persistent">true</prop>
                  <prop key="recovery-delay">1000</prop>
                  <prop key="replication">2</prop>
                </util:properties>
                
                <context:property-placeholder properties-ref="partitionedRegionConfigurationSettings"/>
                
                <gfe:partitioned-region id="Tagger"
                  copies="${replication}"
                  destroy="${destroy}"
                  multicast-enabled="${multicast-enabled}"
                  persistent="${persistent}"
                  recovery-delay="${recovery-delay}"/>
                I will review the 1.3 XSD further and make sure all the simple types are strings. Feel free to create new JIRA tickets for other issues you find. If it involves the <partitioned-region> element, you can just re-open the SGF-211 ticket and append the additional details.
                Last edited by John Blum; Oct 10th, 2013, 04:03 PM.

                Comment


                • svenz
                  svenz commented
                  Editing a comment
                  Thanks for the quick turnaround on this.

              • #9
                @svenz You're welcome.

                I also wanted to let you know (although, you are probably already aware of this) that the validation of the copies attribute on the partitioned-region element (which corresponds to the PartitionAttributes.reduntantCopies property in GemFire) is validated by the underlying PartitionAttributesFactory before the PartitionAttributes instance is created. So, the validation still occurs, but later in the Spring container lifecycle (@ bean creation time vs. parse time) and the configuration error will come from GemFire, like so...

                Code:
                Caused by: java.lang.IllegalStateException: RedundantCopies 4 is an illegal value, please choose a value between 0 and 3
                    at com.gemstone.gemfire.internal.cache.PartitionAttributesImpl.validateAttributes(PartitionAttributesImpl.java:483)
                   ...

                Comment

                Working...
                X