Announcement Announcement Module
Collapse
No announcement yet.
Spring to understand properties in YAML Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring to understand properties in YAML

    YAML makes a lot of sense for properties, and I am using it currently on the project, but have difficulties to inject properties in a

    Code:
    <property name="productName" value="${client.product.name}" />
    fashion.

    Anything I am missing, or I should create a custom YamlPropertyPlaceholderConfigurer ?

    Thank you,
    /Anatoly

  • #2
    What sort of difficulties are you facing? Seems that you're using the PropertyPlaceholder configurer which reads a java.util.Properties object. YAML is used for serialization so as long as the deserialization creates a valid entry inside the source Properties, things should work.

    Comment


    • #3
      @Costin,

      Thank you for replying. Let me try to me more specific on what I would like to achieve. Let's say I have this datasource YAML config:

      datasource.yml:
      Code:
          datasource:
              url: jdbc:hsqldb:file:hsqldb/sample
              username: sa
              password:
              configuration:
                  driver: org.hsqldb.blabla
      I would like to be able to use "property-placeholder":

      Code:
      <context:property-placeholder location="classpath:META-INF/env/props/datasource.yml"/>
      and I would like to access properties in a normal "property-placeholder" way:

      Code:
      <bean id="datasource" class="...">
          <property name="url" value="${datasource.url}"/>
          <property name="username" value="${datasource.username}"/>
          .... .... ....
      </bean>
      Thank you,
      /Anatoly

      Comment


      • #4
        There is no YAML reader out of the box in Spring. Potentially the JSON/YAML Java libraries out there allow these types of files to be read into properties in which case you could plug this into PPC.
        I would recommend this approach since all you need to do is change the way the Properties file is stored rather then the PPC itself (i.e. YamlPropertyPlaceholderConfigurer).

        Comment


        • #5
          @Costin,

          I understand it is beyond a Spring scope, but would you know whether there are any Java library that is able to convert YAML to properties / XML? I looked at snakeyaml, and others, but they do not have such capabilities.

          Again, I understand this is not a Spring related question, but once we have an answer, the Spring will kick in immediately

          Would appreciate any help on this. Thank you,
          /Anatoly

          Comment


          • #6
            I second the need for a YAML PPC. It's possible the Grails folks have already produced code to make this possible.

            Comment


            • #7
              There's no need to implement YamlPropertyPlaceholderConfigurer. I posted article to my dev blog explaining how to read Yaml properties into Spring here http://goo.gl/qg0Oi

              Comment

              Working...
              X