Skip to content

No bean of type ConfigurableEnvironment in AbstractTestNGSpringContextTests [SPR-14834] #19400

Closed

Description

@spring-projects-issues

Andreas Höhmann opened SPR-14834 and commented

I have spring based integration tests, all these tests are based on a base test class which extends org.springframework.test.context.testng.AbstractTestNGSpringContextTests.

If I run all these IT's ... then "sometimes" (I guess if at least one of the test fails) the following test (not all, strange behavior) are also not successful because the whole spring-context startup crash and that because of a missing bean of type "ConfigurableEnvironment" ... yes I have somewhere in the configuration classes code like this:

@Autowired
ConfigurableEnvironment environment;

And in the real world the application have no problem with that :)

But in the test environment there is something strange ... I have no idea :-/

Here is the "important" stuff of that class maybe you see immediately that something is wrong :)

/**
 * Base class for integration tests which require a complete Spring context.
 *
 * <p>
 * Takes care of following aspects:
 * <ul>
 * <li>mark as {@link DirtiesContext}</li>
 * <li>load environment properties from <code>META-INF/spring-test/hscm-environment.properties</code> (are generated during build or must be
 * provided manually in class path)</li>
 * </ul>
 * </p>
 *
 * <p>
 * Loading of environment-properties:
 * <ol>
 * <li>add <b>generated</b> test properties "classpath:META-INF/spring-test/hscm-environment.properties" to simulate "jndi environment", see
 * {@link TestContextLoader}</li>
 * <li>add (optional) customized environment-properties for tests, see {@link TestContextLoader}, see {@link TestEnvironmentProperties}</li>
 * </ol>
 * </p>
 *
 * <p>
 * Currently the whole customizing for HSCM IT's are located inside the test-resources:
 * <ul>
 * <li>default: /hscm/src/test/resources/com/siemens/spice/hscm/test/customizing/hscm-test</li>
 * <li>default: /hscm/src/test/resources/com/siemens/spice/hscm/test/customizing/pcmplus-test</li>
 * <li>for some tests: /hscm/src/test/resources/com/siemens/spice/hscm/test/customizing/hscm-test-freeze</li>
 * <li>for some tests: /hscm/src/test/resources/com/siemens/spice/hscm/test/customizing/pcmplus-test-freeze</li>
 * </ul>
 * </p>
 *
 * <p>
 * You can override every property with the help of the {@link TestEnvironmentProperties} annotation.
 * </p>
 *
 * @author Sebastian Paul
 * @author Andreas Höhmann
 */
@WebAppConfiguration
@ContextConfiguration( //
  locations = { //
      "classpath:META-INF/spring-test/test-applicationContext.xml", //
      "classpath:META-INF/spring-test/test-spring-propertyplaceholder.xml", //
  }, loader = AbstractHscmSpringIntegrationTest.TestContextLoader.class)
@DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD)
@SuppressWarnings("javadoc")
public abstract class AbstractHscmSpringIntegrationTest extends AbstractTestNGSpringContextTests {
....


  // autowired some spring basics
 @Autowired
  protected transient MockHttpServletRequest request;
  @Autowired
  protected transient MockHttpServletResponse response;
  @Autowired
  protected transient WebApplicationContext webApplicationContext;
 
  // but also autowire some core bean which should be available for all tests
  @Autowired
  protected transient HscmConfigurationManager configurationManager;
  @Autowired
  protected transient HscmInitializationManager hscmInitializationManager;

...

@Override
  @AfterMethod(alwaysRun = true)
  protected final synchronized void springTestContextAfterTestMethod(final Method testMethod) throws Exception {
    // FIXME concurrency issues in the TestContext framework - #10532
    LOGGER.debug("Shutdown spring context ...");
    super.springTestContextAfterTestMethod(testMethod);
    LOGGER.debug("Shutdown spring context done");
  }

  @Override
  @BeforeMethod(alwaysRun = true)
  protected final synchronized void springTestContextBeforeTestMethod(final Method testMethod) throws Exception {
    // FIXME concurrency issues in the TestContext framework - #10532
    LOGGER.debug("Start spring context ...");
    super.springTestContextBeforeTestMethod(testMethod);
    LOGGER.debug("Start spring context done");
  }
...
}

Affects: 3.2.17

Issue Links:

Activity

  1. spring-projects-issues commented on Nov 5, 2016

    @spring-projects-issues
    CollaboratorAuthor

    Sam Brannen commented

    This issue is potentially related to #15166, in the sense that parallel construction of an application context results in a null Environment being autowired into an @Configuration class.

  2. spring-projects-issues commented on Nov 5, 2016

    @spring-projects-issues
    CollaboratorAuthor

    Sam Brannen commented

    This issue is a potential duplicate of #10800.

  3. spring-projects-issues commented on Nov 5, 2016

    @spring-projects-issues
    CollaboratorAuthor

    Sam Brannen commented

    This issue is a potential duplicate of #17517.

  4. spring-projects-issues commented on Nov 5, 2016

    @spring-projects-issues
    CollaboratorAuthor

    Sam Brannen commented

    Andreas Höhmann, what happens if you declare a unique suite name for each of your concrete TestNG test classes like follows?

    @Test(suiteName = "my unique suite name for this concrete test class")
    public class ConcreteTests extends AbstractHscmSpringIntegrationTest {
        // ....
    }
  5. spring-projects-issues commented on Apr 6, 2017

    @spring-projects-issues
    CollaboratorAuthor

    Andreas Höhmann commented

    Hey guys... Months later ... I found the problem in our codebase ... there was a kind of "MemoryLeak" ... I guess we can close this here. Never seen this error in our CI since weeks :)

  6. spring-projects-issues commented on Apr 6, 2017

    @spring-projects-issues
    CollaboratorAuthor

    Sam Brannen commented

    OK.

    Thanks for the feedback!

  7. added
    type: bug
    in: test
    on Jan 11, 2019
  8. added
    status: invalid
    on Sep 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

in: teststatus: invalid

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions