Results 1 to 4 of 4

Thread: Web application not picking up default Spring profile settings from context param

  1. #1
    Join Date
    Sep 2004
    Posts
    602

    Default Web application not picking up default Spring profile settings from context param

    Hi

    I have a webflow based application that is using Spring profiles for configuration. My understanding is that I can set a default profile by adding this to web.xml

    Code:
    <context-param>
      	<param-name>spring.profiles.default</param-name>
      	<param-value>development,test</param-value>
    </context-param>
    This doesn't work. Looking at the debug I can see that the context params are not being interrogated as a property source:
    Code:
    DEBUG: org.springframework.core.env.PropertySourcesPropertyResolver - Searching for key 'spring.profiles.default' in [systemEnvironment]
    DEBUG: org.springframework.core.env.PropertySourcesPropertyResolver - Could not find key 'spring.profiles.default' in any property source. Returning [null]
    My app works perfectly if I set the spring.profiles.default as a JVM param, but this defies the point of having a default (it's not really a default if you have to pass it in...).

    Strangely I see that the class DefaultWebEnvironment that I thought was controlling this has been removed in Spring 3.1.1 (it was present in 3.1.0). Does anyone know what's going on here ?

    Javadoc for DefaultWebEnvironment:


    http://static.springsource.org/sprin...vironment.html

    By the way, it seems that, for whatever reason, my web app is initialising a new StandardEnvironment "implementation suitable for use in 'standard' (i.e. non-web)" rather than whatever now replaces the DefaultWebEnvironment.
    Last edited by Paul Newport; Jul 6th, 2012 at 05:28 AM. Reason: Added environment stuff

  2. #2
    Join Date
    Sep 2004
    Posts
    602

    Default

    More info. THis is possibly due to the fact that the beans initialising are in a parent context:

    Code:
        <context-param>
    		<param-name>locatorFactorySelector</param-name>
    		<param-value>classpath:META-INF/spring/beanRefContext.xml</param-value>
    	</context-param>
    	<context-param>
    		<param-name>parentContextKey</param-name>
    		<param-value>ear.context</param-value>
    	</context-param>

  3. #3
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,695

    Default

    It depends for WHAT you want to set the properties. For the ContextLoaderListener you need to set the context-param, for the DispatcherServlet you need to set the init-param of the servlet.

    Also as you already stated you use the BeanFactoryLocater which doesn't know anything of a web context so you need to specify it as a environment variable. It might be that it works as a JNDI attribute.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  4. #4
    Join Date
    Sep 2004
    Posts
    602

    Default

    Quote Originally Posted by Marten Deinum View Post
    It depends for WHAT you want to set the properties. For the ContextLoaderListener you need to set the context-param, for the DispatcherServlet you need to set the init-param of the servlet.

    Also as you already stated you use the BeanFactoryLocater which doesn't know anything of a web context so you need to specify it as a environment variable. It might be that it works as a JNDI attribute.
    Thanks Marten.

Posting Permissions

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