Results 1 to 4 of 4

Thread: reading property file name from other property file

  1. #1
    Join Date
    Jun 2005
    Posts
    10

    Default reading property file name from other property file

    Can we read the name of the property file from other property file

    Something like as below:
    <!--This loads environment.properties properties -->
    Code:
        <bean id="propertyConfigurerBase" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
            <property name="locations">
            	<list>
        	    	<value>/WEB-INF/resources/environment.properties</value>
            	</list>
            </property>
        </bean>
    <!--here I need the name of property file from the above property file-->

    Code:
    <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" name="propertyConfigurerAlias">
            <property name="locations">
            	<list>
    	        	<value>/WEB-INF/resources/$&#123;propertyfileName&#125;</value>        	
            	</list>
            </property>
     </bean>
    Please help me.

    Thanks
    Umesh

  2. #2
    Join Date
    Aug 2004
    Location
    Southampton, UK
    Posts
    826

    Default

    Trying setting the 'order' property of each bean so that the PPC that loads the file name is executed first.

    Rob
    Rob Harrop
    Lead Engineer, dm Server
    SpringSource
    http://www.springsource.com

    Co-Author - Pro Spring

  3. #3
    Join Date
    Jun 2005
    Posts
    10

    Default

    Hi Rob,

    Thanks for quick response.

    Actually I set the order but still I am facing the same problem.

    Here is the details what I did:

    Base applicationcontext.xml, which loads environment.properties

    Code:
     
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http&#58;//www.springframework.org/dtd/spring-beans.dtd">
    
    <!--
      - Root application context for the SpringAppDemo application.
      -->
    <beans>
        <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        	<property name="order" value="1"></property>
            <property name="location" value="/WEB-INF/resources/environment.properties"/>
        </bean>
    </beans>
    applicationcontext-services.xml, which which loads other property file, but it needs the name of propery file from propertyplaceholder

    Code:
     
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http&#58;//www.springframework.org/dtd/spring-beans.dtd">
    
    <!--
      - application context for the SpringAppDemo application.
      -->
    <beans>
        <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" name="propertyConfigurerAlias">
           	<property name="order" value="2"></property>
            <property name="locations">
            	<list>
    	        	<value>/WEB-INF/resources/$&#123;environment&#125;.runtime.properties</value>        	
            	</list>
            </property>
        </bean>
    	<bean id="SendAmoMockService" class="com.pocketthis.orangeukdq.springcontroller.SendAmoMockService">	
    		<property name="debug" value="$&#123;Debug&#125;"/>
    	</bean>
    </beans>
    Now I am configuring them in web.xml as below

    Code:
    				<context-param>
    					<param-name>contextConfigLocation</param-name>
    					<param-value>/WEB-INF/applicationContext.xml /WEB-INF/applicationContext-service.xml</param-value>
    				</context-param>

    Now when I start application the log is as below.



    10:12:22,625 INFO [[/amogateway2]] Loading Spring root WebApplicationContext
    10:12:22,781 INFO [XmlBeanDefinitionReader] Loading XML bean definitions from ServletContext resource [/WEB-INF/applicationContext.xml]
    10:12:22,875 INFO [XmlBeanDefinitionReader] Loading XML bean definitions from ServletContext resource [/WEB-INF/applicationContext-service.xml]
    10:12:22,984 INFO [DefaultListableBeanFactory] Overriding bean definition for bean 'propertyConfigurer': replacing [Root bean with class [org.springframework.beans.factory.config.PropertyP laceholderConfigurer] defined in ServletContext resource [/WEB-INF/applicationContext.xml]] with [Root bean with class [org.springframework.beans.factory.config.PropertyP laceholderConfigurer] defined in ServletContext resource [/WEB-INF/applicationContext-service.xml]]
    10:12:23,000 INFO [XmlWebApplicationContext] Bean factory for application context [Root WebApplicationContext]: org.springframework.beans.factory.support.DefaultL istableBeanFactory defining beans [propertyConfigurer,SendAmoMockService]; root of BeanFactory hierarchy
    10:12:23,031 INFO [XmlWebApplicationContext] 2 beans defined in application context [Root WebApplicationContext]
    10:12:23,031 INFO [DefaultListableBeanFactory] Creating shared instance of singleton bean 'propertyConfigurer'
    10:12:23,156 WARN [AbstractPathResolvingPropertyEditor] Could not resolve placeholder 'environment' in resource path [/WEB-INF/resources/${environment}.runtime.properties] as system property
    10:12:23,156 INFO [PropertyPlaceholderConfigurer] Loading properties file from ServletContext resource [/WEB-INF/resources/${environment}.runtime.properties]
    10:12:23,156 ERROR [ContextLoader] Context initialization failed
    org.springframework.beans.factory.BeanInitializati onException: Could not load properties; nested exception is java.io.FileNotFoundException: Could not open ServletContext resource [/WEB-INF/resources/${environment}.runtime.properties]
    java.io.FileNotFoundException: Could not open ServletContext resource [/WEB-INF/resources/${environment}.runtime.properties]
    at org.springframework.web.context.support.ServletCon textResource.getInputStream(ServletContextResource .java:96)
    at org.springframework.core.io.support.PropertiesLoad erSupport.loadProperties(PropertiesLoaderSupport.j ava:169)
    at org.springframework.core.io.support.PropertiesLoad erSupport.mergeProperties(PropertiesLoaderSupport. java:150)
    It seems earlier properties get overloaded.

    Can you please tell me what am I doing wrong and what is the right way to do this.

    Thanks
    Umesh

  4. #4
    Join Date
    Jun 2005
    Posts
    10

    Default

    Hi Rob,

    Please have a look and and let me know what am I doing wrong.


    Thanks & Regards,
    Umesh

Similar Threads

  1. Order of Bean definitions matters?
    By cfuser in forum Container
    Replies: 2
    Last Post: Oct 21st, 2005, 10:29 AM
  2. Unit testing with JOTM and JtaTransactionManager
    By lalle in forum Architecture
    Replies: 1
    Last Post: Oct 15th, 2005, 09:05 AM
  3. EHCaching Hibernate
    By dencamel in forum Data
    Replies: 3
    Last Post: Sep 6th, 2005, 09:03 PM
  4. Replies: 4
    Last Post: Aug 17th, 2005, 04:42 AM
  5. Replies: 2
    Last Post: May 13th, 2005, 05: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
  •