Announcement Announcement Module
Collapse
No announcement yet.
PropertyPlaceholderConfigurer search in JNDI Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • PropertyPlaceholderConfigurer search in JNDI

    Code:
        <bean id="propertyConfigurer" 
          class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> 
          <property name="locations"> 
             <list> 
             <value>classes/datasource/DataSourceTypes.properties</value> 
             <!--<value>classpath&#58;deployment.properties</value> --> 
                 
             </list> 
          </property> 
       </bean>
    I have one properties file in JNDI (not in the classpath). So I want PropertyPlaceHolderConfigurer to search in JNDI for that properties file and replace the keys from that properties file

    Is it possible?

    Any help will be greatly appreciated..
    Thanks,
    SSSS.

  • #2
    By default, the Resoure abstraction is used with the PropertyPlacheolderConfigurer. How did you store the properties file in JNDI (a Properties object or a String)?

    I think it'd be possible to create a jndi Resource abstraction in order to allow you to do something like this:

    <value>jndi:java:/comp/env/MyProperties</value>

    Coudl you please elaborate on how you've stored the properties file in JNDI?

    rgds,
    Alef

    Comment


    • #3
      This tag is in the Jboss App servers Jboss_service.xml
      Code:
       <!-- ==================================================================== -->
        <!-- Deployment Scanning                                                  -->
        <!-- ==================================================================== -->
        <mbean code="org.jboss.naming.ExternalContext"
               name="jboss.jndi&#58;service=ExternalContext,jndiName=external/config">
            <attribute name="JndiName">deploymentConfig</attribute>
            <attribute name="Properties">
                java.naming.factory.initial=com.sun.jndi.fscontext.FSContextFactory
                java.naming.provider.url=file&#58;///c&#58;/config/
            </attribute>
            <attribute name="InitialContext">javax.naming.InitialContext</attribute>
        </mbean>
      This is how i am binding the path with the jndi name which has to be accessed by the application context's PropertyPlaceHolder tag.[code]

      Comment


      • #4
        I would absolutely LOVE to have this exact same thing. We use the PropertyPlaceholderConfigurer solely for the purpose of using different DB, JMS, etc. settings as we migrate application deployments from Dev->Test->Prod. We currently have a file location on each box with different files but we have needed to move to JNDI for a long time. This would be an excellent solution to this problem.

        Comment


        • #5
          Errrr, I didn't think long enough I guess ... Here's the solution:

          Code:
          <bean class="org.sprfr.PropertyPlaceholderConfigurer">
            <property name="properties">
              <bean class="org.sprfr.jndi.JndiObjectFactoryBean">
                <property name="jndiName"><value>JNDI-reference</value></property>
              </bean>
            </property>
          </bean>
          The JndiObjectFactoryBean pulls a jndi object from the JNDI tree (it's a Properties object so that's fine). JNDI-reference needs to be replaced by your JNDI location (something like java:comp/env/external/config I guess?). The 'properties' property of the PropertyPlaceholderConfigurer takes a Properties object instead of a Resource.

          Let me know if you have any issues with this...

          rgds,
          Alef

          Comment


          • #6
            still i get a problem

            jboss-service.xml

            <mbean code="org.jboss.naming.ExternalContext"
            name="jboss.jndi:service=ExternalContext,jndiName= external/config">
            <attribute name="JndiName">external/config</attribute>
            <attribute name="Properties">
            java.naming.factory.initial=com.sun.jndi.fscontext .FSContextFactory
            java.naming.provider.url=file:///c:/config/
            </attribute>
            <attribute name="InitialContext">javax.naming.InitialContext</attribute>
            </mbean>

            applicationcontext.xml

            <bean id="propertyConfigurer"
            class="org.springframework.beans.factory.config.Pr opertyPlaceholderConfigurer">
            <property name="properties">
            <bean
            class="org.springframework.jndi.JndiObjectFactoryB ean">
            <property name="jndiName">
            <value>external/config/deployment.properties</value>
            </property>
            </bean>
            </property>


            I get the following errors.
            ceptionsException (1 errors); nested propertyAccessExceptions are: [org.springframework.beans.TypeMismatchException: Failed to convert property value of type [com.sun.jndi.fscontext.FSContext$FSFile] to required type [java.util.Properties] for property 'properties'])

            I need your suggestion.Is there any other way to refer JNDI for loading property files?

            Comment


            • #7
              Arghhh, it's a file. I didn't realize this.

              You should be able to next the JndiObjectFactoryBean in a FileSystemResource (this takes a File object):

              <bean class="org.sprfr.PropertyPlaceholderConfigurer">
              <property name="properties">
              <bean class="org.sprfr.core.io.FileSystemResource">
              <constructor-arg>
              <bean class="org.sprfr.jndi.JndiObjectFactoryBean">
              <property name="jndiName"><value>external/config/deployment.properties</value></property>
              </bean>
              </constructor-arg>
              </bean>
              </property>
              </bean>

              It's getting a bit bloated here. If I have time I'll think of a more elegant solution.

              If it doesn't work, please don't hesitate to reply!

              rgds,
              Alef Arendsen

              Comment


              • #8
                Hi
                I get the Class cast Exception using the sollution setting property "properties" but this one is working fine

                <bean id="jndiPropertyConfigurer"
                class="org.springframework.beans.factory.config.Pr opertyPlaceholderConfigurer">
                <property name="locations">
                <list>
                <bean
                class="org.springframework.core.io.FileSystemResou rce">
                <constructor-arg>
                <bean
                class="org.springframework.jndi.JndiObjectFactoryB ean">
                <property name="jndiName"
                value="java:comp/env/propertyFileName" />
                <property name="resourceRef" value="true" />
                </bean>
                </constructor-arg>
                </bean>
                </list>
                </property>
                <property name="ignoreUnresolvablePlaceholders" value="true" />
                </bean>
                Last edited by [email protected]; Aug 2nd, 2007, 03:07 AM.

                Comment


                • #10
                  Finally it worked just fine! Here's the sample spring bean config file :

                  <bean id="jndiPropertyConfigurer" class="org.springframework.beans.factory.config.Pr opertyPlaceholderConfigurer">
                  <property name="locations">
                  <list>
                  <bean class="org.springframework.core.io.FileSystemResou rce">
                  <constructor-arg>
                  <bean class="org.springframework.jndi.JndiObjectFactoryB ean">
                  <property name="jndiName" value="CONFIG_FILE_SPRING" />
                  <property name="resourceRef" value="false" />
                  </bean>
                  </constructor-arg>
                  </bean>
                  <bean class="org.springframework.core.io.FileSystemResou rce">
                  <constructor-arg>
                  <bean class="org.springframework.jndi.JndiObjectFactoryB ean">
                  <property name="jndiName" value="CONFIG_FILE_APP" />
                  <property name="resourceRef" value="false" />
                  </bean>
                  </constructor-arg>
                  </bean>
                  </list>
                  </property>
                  </bean>

                  Comment


                  • #11
                    Can someone explain to me how you load the properties file into JNDI on a Weblogic server?

                    I'm going to be honest here and say I really do not know much about JNDI, so I'm sorry if the answer is obvious, but I can not figure it out.

                    Comment


                    • #12
                      PropertyPlaceHolderConfigurer search in JNDI

                      I had the same issue (wanting to use a JNDI-sourced value to determine where my PropertyPlaceHolderConfigurer property files are located) and uses the concepts here: http://jira.springframework.org/browse/SPR-3030
                      to add JNDI-awareness to the PropertyPlaceHolderConfigurer for it's own locations property as well as normal placeHolder expansion anywhere else in the bean configuration.

                      That allows me to have a jndi environment value like:

                      Code:
                        <Environment 
                          name="configDirectory"
                          type="java.lang.String"
                          value="\path\to\my\config-directory\for-this-environment" />
                      And spring configuration like
                      Code:
                        
                      <bean
                          id="propertyPlaceholderConfigurer"    class="org.springframework.beans.factory.config.JndiAwarePropertyPlaceholderConfigurer"
                          init-method="initialize">
                          <property
                            name="locations">
                            <list>
                              <value>file:${configDirectory}/../common.properties
                              </value>
                              <value>file:${configDirectory}/application.properties
                              </value>
                            </list>
                          </property>
                        </bean>
                      where the value for ${configDirectory} is sourced from JNDI

                      The placeHolder expansion for locations only kicks in for ones of type UrlResource as they're the only ones I have... the mileage for others will vary.

                      The actual code use is attached (hopefully)

                      Comment


                      • #13
                        <mbean code="org.jboss.naming.ExternalContext"
                        name="jboss.jndi:service=ExternalContext,jndiName= external/config">
                        <attribute name="JndiName">external/config</attribute>
                        <attribute name="Properties">
                        java.naming.factory.initial=com.sun.jndi.fscontext .FSContextFactory
                        java.naming.provider.url=file:///c:/config/
                        </attribute>
                        <attribute name="InitialContext">javax.naming.InitialContext</attribute>
                        </mbean>

                        applicationcontext.xml

                        <bean id="propertyConfigurer"
                        class="org.springframework.beans.factory.config.Pr opertyPlaceholderConfigurer">
                        <property name="properties">
                        <bean
                        class="org.springframework.jndi.JndiObjectFactoryB ean">
                        <property name="jndiName">
                        <value>external/config/deployment.properties</value>
                        </property>
                        </bean>
                        </property>

                        Resveratrol

                        Comment

                        Working...
                        X