Spring Framework
  1. Spring Framework
  2. SPR-9035

Profiles not discovered by DispatcherServlet Config

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Works as Designed
    • Affects Version/s: 3.1 GA
    • Fix Version/s: None
    • Component/s: Core
    • Labels:
      None
    • Last commented by a User:
      false

      Description

      The Spring blog http://blog.springsource.org/2011/02/11/spring-framework-3-1-m1-released/ references the ability to configure "spring.profiles.active" as an "init-param" for DispatcherServlet. This feature does not work with DispatcherServlet, it does work with ContextLoaderListener.

      Web.xml servlet section:
      <servlet>
      <servlet-name>accounts</servlet-name>
      <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>

      <init-param>
      <param-name>contextConfigLocation</param-name>
      <param-value>/WEB-INF/mvc-config.xml</param-value>
      </init-param>
      <init-param>
      <param-name>spring.profiles.active</param-name>
      <param-value>PRODUCKSEAN</param-value>
      </init-param>
      <load-on-startup>1</load-on-startup>
      </servlet>

        Activity

        Hide
        Chris Beams added a comment -

        Hi Gordon,

        See https://github.com/SpringSource/spring-framework-issues/tree/master/SPR-9035.

        Resolving this as 'works as designed', because I assume you're setting 'spring.profiles.active' as an init-param against the DispatcherServlet, but expecting that profile to be activated not only against the dispatcher servlet child application context, but also against the root application context. It doesn't work that way. Setting the spring.profiles.active as a context-param will cause it to be inherited by the child application, but not the other way around.

        The reproduction project above proves that beans declared in the servlet's own context do get picked up properly when spring.profiles.active is specified.

        Of course, feel free to reopen if there's something I've missed here.

        Cheers,

        Chris

        Show
        Chris Beams added a comment - Hi Gordon, See https://github.com/SpringSource/spring-framework-issues/tree/master/SPR-9035 . Resolving this as 'works as designed', because I assume you're setting 'spring.profiles.active' as an init-param against the DispatcherServlet, but expecting that profile to be activated not only against the dispatcher servlet child application context, but also against the root application context. It doesn't work that way. Setting the spring.profiles.active as a context-param will cause it to be inherited by the child application, but not the other way around. The reproduction project above proves that beans declared in the servlet's own context do get picked up properly when spring.profiles.active is specified. Of course, feel free to reopen if there's something I've missed here. Cheers, Chris

          People

          • Assignee:
            Chris Beams
            Reporter:
            Gordon Dickens
            Last updater:
            Trevor Marshall
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:
              Days since last comment:
              2 years, 11 weeks, 4 days ago