Class TestContextSpringFactoriesUtils

java.lang.Object
org.springframework.test.context.util.TestContextSpringFactoriesUtils

public abstract class TestContextSpringFactoriesUtils extends Object
Collection of utilities for working with SpringFactoriesLoader within the Spring TestContext Framework.

Primarily intended for use within the TestContext framework.

Since:
6.0
Author:
Sam Brannen
  • Method Details

    • loadFactoryImplementations

      public static <T> List<T> loadFactoryImplementations(Class<T> factoryType)
      Load factory implementations of the given type via the SpringFactoriesLoader mechanism.

      This method utilizes a custom SpringFactoriesLoader.FailureHandler and DEBUG/TRACE logging that are specific to the needs of the Spring TestContext Framework.

      Specifically, this method looks up and instantiates all factoryType entries configured in all META-INF/spring.factories files on the classpath.

      If a particular factory implementation cannot be loaded due to a LinkageError or ClassNotFoundException, a DEBUG message will be logged, but the associated exception will not be rethrown. A RuntimeException or any other Error will be rethrown. Any other exception will be thrown wrapped in an IllegalStateException.

      Type Parameters:
      T - the factory type
      Parameters:
      factoryType - the interface or abstract class representing the factory
      Returns:
      an unmodifiable list of factory implementations
      See Also:
      • SpringFactoriesLoader.forDefaultResourceLocation(ClassLoader)
      • SpringFactoriesLoader.load(Class, org.springframework.core.io.support.SpringFactoriesLoader.FailureHandler)