Announcement Announcement Module
Collapse
No announcement yet.
context:property-placeholder does not work Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • context:property-placeholder does not work

    Hi, I tried hard a lot of hours maybe someone can help me.
    I simply want to outsource configuration.

    I have the following in my applicationContext.xml
    Code:
    <context:property-placeholder location="/resources/jacavi.properties"/>
    
    <bean id="testBean" class="java.lang.String">
    	 <constructor-arg><value>${test}</value></constructor-arg>
    </bean>
    as location i also tried "file:/resources/jacavi.properties", "javavi.properties", "file:jacavi.properties", "classpath*:jacavi.properties", "classpath*:/resources/jacavi.properties", and so on.

    my jacavi.properties looks like:
    test=hello world

    when I get my testBean and print it out it gives me ${test} and not the expected hello world.

    what am I doing wrong?


    cheers Flo

  • #2
    Originally posted by flosk8 View Post
    Hi, I tried hard a lot of hours maybe someone can help me.
    I simply want to outsource configuration.
    Code:
    <context:property-placeholder
    		location="classpath:application.properties" />
    And then add the directory that the properties file is in to your apps classpath
    Last edited by Paul Newport; Sep 19th, 2008, 04:25 AM. Reason: added code tag

    Comment


    • #3
      Originally posted by Paul Newport View Post
      Code:
      <context:property-placeholder
      		location="classpath:application.properties" />
      And then add the directory that the properties file is in to your apps classpath
      Hi Paul no effect. still the same. I still got only the string ${test} on my console. I added the resources folder where my applicationContext.xml and my jacavi.properties lies to the classpath but it still doesnot work any ideas?

      cheers

      Comment


      • #4
        Originally posted by flosk8 View Post
        Hi Paul no effect. still the same. I still got only the string ${test} on my console. I added the resources folder where my applicationContext.xml and my jacavi.properties lies to the classpath but it still doesnot work any ideas?

        cheers
        It's not possible to get the behavior you described with the mentioned config because:
        1. If PPC is not possible to load a properties, exception is thrown during context instantiation. So, you application.properties resource is found and properties are loaded;
        2. If PPC is not able to resolve a bean property, exception is thrown. Hence, it's not allowed for bean to have an unresolved property at ${...} format if PPC is defined;

        Comment


        • #5
          Originally posted by denis.zhdanov View Post
          It's not possible to get the behavior you described with the mentioned config because:
          1. If PPC is not possible to load a properties, exception is thrown during context instantiation. So, you application.properties resource is found and properties are loaded;
          2. If PPC is not able to resolve a bean property, exception is thrown. Hence, it's not allowed for bean to have an unresolved property at ${...} format if PPC is defined;
          Hi Denis, what is PPC and how can i define it. I dont have any exceptions and i could load my bean but it gives my ${test} and not the value test is mapping to. If i write ${somthingbad} I also get no error (something bad isnot part of application.properties).

          cheers

          Comment


          • #6
            PPC is a PropertyPlaceHolderConfigurer

            You can do the following - define a PropertyPlaceHolderConfigurer bean directly at the config (i.e. don't use <contextroperty-placeholder> element). You can find an example of how to do that at the reference - 3.7.2.1. Example: the PropertyPlaceholderConfigurer. If you still have the same behavior (the bean holds ${..} property), check PPC content via debugger. It should contain resolved Properties object with resolved properties.

            Comment


            • #7
              Originally posted by denis.zhdanov View Post
              PPC is a PropertyPlaceHolderConfigurer

              You can do the following - define a PropertyPlaceHolderConfigurer bean directly at the config (i.e. don't use <contextroperty-placeholder> element). You can find an example of how to do that at the reference - Example: the PropertyPlaceholderConfigurer[/URL]. If you still have the same behavior (the bean holds ${..} property), check PPC content via debugger. It should contain resolved Properties object with resolved properties.
              Hi denis,

              I tried the following.

              Code:
              <bean id="propLoader" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
                  	<property name="locations">
                      	<value>classpath:test.properties</value>
                  	</property>
              	</bean>
              test.properties does not exist but i dont get an exception or annything else.

              with the following in debugging
              Code:
              <bean id="propLoader" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
                  	<property name="locations">
                      	<value>classpath:jacavi.properties</value>
                  	</property>
              	</bean>
              localProperties of propLoader is null and in all the other members I can not find the stuff of my properties file.

              Still anny ideas?

              cheers

              Flo

              Comment


              • #8
                How're you building the container? Do you use ApplicationContext or BeanFactory?

                Comment


                • #9
                  Originally posted by denis.zhdanov View Post
                  How're you building the container? Do you use ApplicationContext or BeanFactory?
                  Thank you very much ma man we user the BeanFactory now we use ApplicationContext and it works fine.

                  cheers

                  Comment

                  Working...
                  X