Results 1 to 5 of 5

Thread: Override for WebApplicationContext.CONFIG_LOCATION_PARAM

  1. #1
    Join Date
    Aug 2004
    Posts
    26

    Default Override for WebApplicationContext.CONFIG_LOCATION_PARAM

    Hi,

    I would like to have a system property (or some other external means) to override the WebApplicationContext.CONFIG_LOCATION_PARAM
    so I can have multiple Spring configurations for one Web Application.

    The reason I would like this is that I want to integration test my web application without a database using stubs for my DAO's. I would have two context parameters:
    contextConfigLocation=
    /WEB-INF/applicationContext.xml classpath:dao.xml
    testContextConfigLocation=
    /WEB-INF/applicationContext.xml classpath:stubdao.xml

    I feel this may be generally useful and would like to see it included in Spring. Does anyone else agree or is there already a way of achieving what I need?

    Regards,
    Gordon.

  2. #2
    Join Date
    Aug 2004
    Location
    Montréal, Canada
    Posts
    845

    Default

    I can not find CONTEXT_CLASS_PARAM in WebApplicationContext. Are you talking about
    Code:
    ContextLoader.CONTEXT_CLASS_PARAM
    in this case, you can easily overide the default value in your web.xml
    Code:
      <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
          /WEB-INF/dataAccessContext-local.xml  /WEB-INF/applicationContext.xml
        </param-value>
      </context-param>
    Omar Irbouh

    Spring Modules Team
    http://irbouh.blogspot.com/

  3. #3
    Join Date
    Aug 2004
    Posts
    26

    Default

    my humblest apologies - I meant
    Code:
    org.springframework.web.context.ContextLoader
    The whole point is NOT to override the contextConfigLocation parameter in web.xml as I don't want to have to keep changing it depending on what mode I am working in - instead I will have two server instances running exactly the same application with different Spring configurations.

  4. #4
    Join Date
    Aug 2004
    Location
    Toronto, Canada
    Posts
    736

    Default

    Well, the contextConfigLocation _is_ an override.

    I don't see this as fundamentally different than any number of other things that can come from a file, and it's not an option to make all of them settable as system properties too. Additionally, the system property approach has a big problem too since then you can't have multiple web-apps running in that one appserver, and have different settings for each.

    What I would recommend instead, is to just use a shell script of some sort that allows you to toggle it one way vs. another, via a regexp search/replace. The default build would be for production, and for testing you would reconfigure it.

    Regards,
    Colin Sampaleanu
    SpringSource - http://www.springsource.com

  5. #5
    Join Date
    Aug 2004
    Posts
    8

    Default

    In fact, elegant switching between real and mock implementations can be achieved rather easily using Ant's <filter> and <switch> tasks: Add a property deployment.mode to your build script and use different filters for replacing the context parameter @contextConfigLocation@ with the appropriate path in your web.xml, based on whether the value of ${deployment.mode} is "mock" or "real". The build process is where to do this, not the application itself, so this is nothing the framwork should care about or provide means for.

Similar Threads

  1. How to override a property of list type
    By duplau in forum Container
    Replies: 2
    Last Post: Nov 17th, 2006, 10:33 AM
  2. Replies: 9
    Last Post: Aug 26th, 2005, 07:57 AM
  3. Override JdbcDaoImpl trouble
    By reggie in forum Security
    Replies: 4
    Last Post: Aug 8th, 2005, 02:21 PM
  4. flowExecutionManager -- to override or not?
    By Dave Syer in forum Web Flow
    Replies: 1
    Last Post: Jul 20th, 2005, 09:24 AM
  5. Replies: 0
    Last Post: Oct 4th, 2004, 11:11 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
  •