Results 1 to 3 of 3

Thread: Spring 3.0.5+Junit 4.8.2 Setting system properties before @ContextConfiguration

  1. #1
    Join Date
    Feb 2012
    Posts
    2

    Default Spring 3.0.5+Junit 4.8.2 Setting system properties before @ContextConfiguration

    Hi all, first post here.

    I'm in the process of restructuring our test cases and want to take advantage of some of the features in spring 3.0.5 and junit 4.8.2. Our current application is set up using a PropertyPlaceholderConfigurer which looks at three potential properties files - a master file, an environment specific file (eg. dev, stage. prod) and an overrides file. In order for our PropertyPlaceholderConfigurer to find these files, two system properties must be set before the context is loaded - runtime.env and overrides.

    My question is this: can we set system properties before the @ContextConfiguration{location=} gets triggered?

    Thanks.

  2. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,625

    Default

    Use a method annotated with @BeforeClass that is your only way unless you want to write your own TestExecutionListener.
    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

  3. #3
    Join Date
    Jun 2007
    Posts
    12

    Default

    Quote Originally Posted by persistance View Post
    Hi all, first post here.

    I'm in the process of restructuring our test cases and want to take advantage of some of the features in spring 3.0.5 and junit 4.8.2. Our current application is set up using a PropertyPlaceholderConfigurer which looks at three potential properties files - a master file, an environment specific file (eg. dev, stage. prod) and an overrides file. In order for our PropertyPlaceholderConfigurer to find these files, two system properties must be set before the context is loaded - runtime.env and overrides.

    My question is this: can we set system properties before the @ContextConfiguration{location=} gets triggered?

    Thanks.
    You can just create a static block to do this.

    static {
    System.setProperty("myProp", "myPropValue");
    }

Posting Permissions

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