Announcement Announcement Module
Collapse
No announcement yet.
Issue with Spring profiles and my properties files Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • #16
    What do you mean by "icm"?

    Otherwise, your point about configuring the PropertySourcesPlaceholderConfigurer manually is relevant: I now get another error:

    Code:
    org.springframework.beans.factory.BeanInitializationException: Could not load properties; nested exception is java.io.FileNotFoundException: Could not open ServletContext resource [/classpath*:META-INF/spring/default/*.properties]
    with the following config:
    Code:
    <bean class="org.springframework.context.support.PropertySourcesPlaceholderConfigurer">
    	<property name="location" value="classpath*:META-INF/spring/default/*.properties"/>
    	<property name="ignoreUnresolvablePlaceholders" value="true" />
    </bean>
    In both webmvc-config.xml and applicationContext.xml...

    Comment


    • #17
      I shouldn't mix dutch abbreviations into English sentences . In combination with is what I was about to type.

      Just did a quick test (spring 3.1.3) and works like a charm, at least from a unit test. So not sure why it doesn't work in web environment.

      Try removing the * from classpath*: see if that works. In general classpath*: is only useful if you want to load resources from jar files.

      Comment


      • #18
        Unfortunately, it does not make any difference...

        Here is my new config:
        Code:
        <beans profile="default">
        	<bean class="org.springframework.context.support.PropertySourcesPlaceholderConfigurer">
        		<property name="location" value="classpath:META-INF/spring/default/*.properties"/>
        		<property name="ignoreUnresolvablePlaceholders" value="true" />
        	</bean>
        </beans>
        and the resulting exception:
        Code:
        GRAVE: Exception lors de l'envoi de l'évènement contexte initialisé (context initialized) à l'instance de classe d'écoute (listener) org.springframework.web.context.ContextLoaderListener
        org.springframework.beans.factory.BeanInitializationException: Could not load properties; nested exception is java.io.FileNotFoundException: class path resource [META-INF/spring/default/*.properties] 
        cannot be opened because it does not exist
        I use Spring 3.2.0...

        Comment


        • #19
          I figured you would also check the stacktrace and see that *.properties isn't a valid filename... Change to the properties file needed..

          Comment


          • #20
            Yes. I had actually figured this out after posting my last thread.

            I changed to :
            Code:
            <property name="location" value="classpath:META-INF/spring/default/app-config.properties" />
            And I get the same error as before i.e.:

            Code:
            Could not autowire field: private java.lang.String com.kadjoukor.service.MailerServiceImpl.websiteContext; nested exception is java.lang.IllegalArgumentException: Could not resolv
            e placeholder 'application.url' in string value "${application.url}"
            event though the content of app-config.properties is as follows:
            app-config.properties:
            Code:
            application.url=http://localhost:8080/kadjoukor
            Back to square one...

            Comment


            • #21
              Strange.. My test is working as expected with the exact same setup only difference is I run it from a testcase and not a web application. But in theory the behavior should be the same.

              Comment


              • #22
                Hi Marten!

                I actually decided to give up (temporarily) on this issue and tried to switch back to a config without profiles.

                Then I realized that the issue was elsewhere. For some reason, Spring does not like this:
                Code:
                <context:property-placeholder location="classpath*:META-INF/spring/*.properties" />
                <context:property-placeholder location="classpath*:META-INF/spring/default/*.properties" />
                Notice the nested "default" directory.

                I had forgotten to mention the presence of the first line (above) in my original post because I deemed it irrelevant (sorry about that)...

                Comment


                • #23
                  The problem with that is that by default a property-placeholder resolves ALL placeholders if one cannot be found it throws an exception. You have 2 solutions for this.

                  1. set the property ignore-unresolvable to true on at least the first placeholder (however order is basically undetermined so you might need to set them on both)

                  2. Use a single property-placeholder which loads files from both location, use a , seperated location for that (simply putting both in).

                  Comment


                  • #24
                    Thanks Marten. That fixed it!

                    Comment

                    Working...
                    X