Class SpringFactory

java.lang.Object
io.cucumber.spring.SpringFactory
All Implemented Interfaces:
io.cucumber.core.backend.Container, io.cucumber.core.backend.Lookup, io.cucumber.core.backend.ObjectFactory

@API(status=STABLE) public final class SpringFactory extends Object implements io.cucumber.core.backend.ObjectFactory
Spring based implementation of ObjectFactory.

Application beans are accessible from the step definitions using autowiring (with annotations).

The spring context can be configured by annotating one glue class with a @CucumberContextConfiguration and any one of the following @ContextConfiguration, @ContextHierarchy or @BootstrapWith. This glue class can also be annotated with @WebAppConfiguration or @DirtiesContext annotation.

Notes:

  • SpringFactory uses Springs TestContextManager framework to manage the spring context. The class annotated with CucumberContextConfiguration will be use to instantiate the TestContextManager.
  • If not exactly one glue class is annotated with CucumberContextConfiguration an exception will be thrown.
  • Step definitions should not be annotated with @Component or other annotations that mark it as eligible for detection by classpath scanning. When a step definition class is annotated by @Component or an annotation that has the @Component stereotype an exception will be thrown
  • Constructor Details

    • SpringFactory

      public SpringFactory()
  • Method Details

    • addClass

      public boolean addClass(Class<?> stepClass)
      Specified by:
      addClass in interface io.cucumber.core.backend.Container
    • start

      public void start()
      Specified by:
      start in interface io.cucumber.core.backend.ObjectFactory
    • stop

      public void stop()
      Specified by:
      stop in interface io.cucumber.core.backend.ObjectFactory
    • getInstance

      public <T> T getInstance(Class<T> type)
      Specified by:
      getInstance in interface io.cucumber.core.backend.Lookup