Page 1 of 2 12 LastLast
Results 1 to 10 of 13

Thread: PropertyPlaceholderConfigurer search in JNDI

  1. #1
    Join Date
    Mar 2005
    Posts
    7

    Default 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. #2
    Join Date
    Aug 2004
    Location
    Amsterdam, Netherlands
    Posts
    450

    Default

    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
    Alef Arendsen
    SpringSource
    http://www.springsource.com

  3. #3
    Join Date
    Mar 2005
    Posts
    7

    Default

    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]

  4. #4
    Join Date
    Apr 2005
    Location
    Jacksonville, FL
    Posts
    1

    Default

    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.
    Chris

  5. #5
    Join Date
    Aug 2004
    Location
    Amsterdam, Netherlands
    Posts
    450

    Default

    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
    Alef Arendsen
    SpringSource
    http://www.springsource.com

  6. #6
    Join Date
    Mar 2005
    Posts
    7

    Default 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?

  7. #7
    Join Date
    Aug 2004
    Location
    Amsterdam, Netherlands
    Posts
    450

    Default

    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
    Alef Arendsen
    SpringSource
    http://www.springsource.com

  8. #8

    Default

    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 c.petz@efkon.com; Aug 2nd, 2007 at 02:07 AM.

  9. #9
    Join Date
    Mar 2008
    Posts
    2

    Default

    Alef and c.petz@efkon.com

    Thanks a lot for the solutions. I have exactly the same requirement. It does not work for me yet (may be app server specific jndi issue) but you can ask Spring to create appropriate Class to do this simply as it looks to be a general requirement.

  10. #10
    Join Date
    Mar 2008
    Posts
    2

    Default

    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>

Similar Threads

  1. Replies: 13
    Last Post: Feb 5th, 2010, 12:31 AM
  2. Replies: 3
    Last Post: Jul 3rd, 2006, 12:27 PM
  3. LDAPPasswordAuthenticationDao problem
    By benoit_m35 in forum Security
    Replies: 15
    Last Post: Jan 11th, 2006, 07:04 AM
  4. Replies: 2
    Last Post: Sep 20th, 2005, 12:59 AM
  5. Stack Overflow
    By rayho222 in forum Container
    Replies: 6
    Last Post: May 17th, 2005, 03:42 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •