Skip to content

SpringContexts not properly closed after test-class is finished [SPR-11363] #15989

Closed

Description

@spring-projects-issues

Andreas Eternach opened SPR-11363 and commented

Hello,

i have two test classes:

First testclass: derived from class AbstractTestNGSpringContextTests, uses annotation @EnableSpringConfigured

Second testclass: plain TestNG-Test without spring context, tries to instantiate a @Configurable-annotated-class

Maven runs the testcases in the order given above. When the second testclass is run and the @Configurable-annotated-class is constructed, a NoSuchBeanDefinitionEception is thrown.

I assume that the spring-context of the first testclass is not automatically destroyed.

Further investigation showed:

  1. adding @DiritiesContext to the first testclass resolves the problem.
  2. running AnnotationBeanConfigurerAspect.aspectOf().destroy() before the second test-class is executed resolves the problem.

Best Regards, Andreas


Affects: 3.2.6

Issue Links:

Activity

  1. spring-projects-issues commented on Jan 31, 2014

    @spring-projects-issues
    CollaboratorAuthor

    Sam Brannen commented

    This issue duplicates #10789, with regard to support for @Configurable across test classes within a test suite.

    Regarding not properly closing a context after a test class has finished, this is in fact by design and one of the key features of the Spring TestContext Framework (TCF). Namely, the TCF caches contexts across all test methods and test classes within a test suite unless a test method or test class is explicitly configured with @DirtiesContext. For details on caching support in the TCF, please refer to the Context caching section of the reference manual.

  2. added
    type: bug
    in: test
    status: duplicate
    on Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

in: teststatus: duplicate

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions