Package io.cucumber.spring
Class SpringFactory
- java.lang.Object
-
- io.cucumber.spring.SpringFactory
-
- All Implemented Interfaces:
Container
,Lookup
,ObjectFactory
@API(status=STABLE) public final class SpringFactory extends Object implements ObjectFactory
Spring based implementation of ObjectFactory.Application beans are accessible from the step definitions using autowiring (with annotations).
SpringFactory uses TestContextManager to manage the spring context. The step definitions are added to the TestContextManagers context and the context is reloaded for each scenario.
The spring context can be configured by:
- Annotating one step definition with: @
ContextConfiguration
, @ContextHierarchy
or @BootstrapWith
. This step definition can also be annotated with @WebAppConfiguration
or @DirtiesContext
annotation. - If no step definition class with @ContextConfiguration or @ContextHierarchy is found, it will try to load cucumber.xml from the classpath.
Notes:
-
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 - If more that one step definition class is used to configure the spring context an exception will be thrown.
-
-
Constructor Summary
Constructors Constructor Description SpringFactory()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
addClass(Class<?> stepClass)
<T> T
getInstance(Class<T> type)
void
start()
void
stop()
-
-
-
Method Detail
-
start
public void start()
- Specified by:
start
in interfaceObjectFactory
-
stop
public void stop()
- Specified by:
stop
in interfaceObjectFactory
-
getInstance
public <T> T getInstance(Class<T> type)
- Specified by:
getInstance
in interfaceLookup
-
-