Announcement Announcement Module
Collapse
No announcement yet.
Spring JUnit test - Context not reloading Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring JUnit test - Context not reloading

    Hi Guys,

    My applicationContext is not reloading every time I run my test. I made some changes to my applicationContext.xml file and the change is not reflected at all. I tried @DirtiesContext at the class level too.

    Code:
    @RunWith(SpringJUnit4ClassRunner.class)
    @ContextConfiguration(locations = "../../../../applicationContext.xml")
    @TestExecutionListeners({DependencyInjectionTestExecutionListener.class, DirtiesContextTestExecutionListener.class})
    @DirtiesContext
    public class RunTests   {
    Any help or suggestions would be appreciated.

    Regards,
    Jerry.

  • #2
    More details..

    To be more clear... I deleted all the bean definitions in my applicationContext.xml and the tests still run with the cached copy..

    Waiting for some help...

    Comment


    • #3
      Are you using Spring 2.5.x or Spring 3.0.x?

      FYI: @DirtiesContext is not supported at the class level in Spring 2.5. I didn't add class-level support until 3.0. In Spring 3.0 @DirtiesContext supports class modes as well via the classMode attribute.

      When you say that you "deleted all the bean definitions", what do you mean exactly? Did you modify the physical XML file in the file system?

      - Sam

      Comment


      • #4
        Originally posted by Sam Brannen View Post
        Are you using Spring 2.5.x or Spring 3.0.x?

        FYI: @DirtiesContext is not supported at the class level in Spring 2.5. I didn't add class-level support until 3.0. In Spring 3.0 @DirtiesContext supports class modes as well via the classMode attribute.

        When you say that you "deleted all the bean definitions", what do you mean exactly? Did you modify the physical XML file in the file system?

        - Sam
        Sam,

        Thank you for you reply. I am using Spring 3.0.X and so class level DirtiesContext is supported. Yes.. I modified the physical XML file in the file system.

        By the way, I made it work but this is how -

        @RunWith(SpringJUnit4ClassRunner.class)
        @ContextConfiguration(locations = "file:src/applicationContext.xml")

        Regards,
        Jerry.

        Comment


        • #5
          Originally posted by jerryragland View Post
          @RunWith(SpringJUnit4ClassRunner.class)
          @ContextConfiguration(locations = "file:src/applicationContext.xml")
          If that's how you got it to work, it may have been a caching problem involving classpath resources. Have you tried refreshing and cleaning your project (i.e., instructing your IDE to rebuild your project)?

          Also, if applicationContext.xml is in the root of your classpath, you should simply reference it via an absolute path (like below) and not relative with all of those "../" elements.

          Code:
          @ContextConfiguration("/applicationContext.xml")
          - Sam

          p.s. although any type of resource is supported (e.g., file:...), classpath resources are preferred due to increased robustness and portability.

          Comment

          Working...
          X