Package net.officefloor.spring
Class SpringSupplierSource
java.lang.Object
net.officefloor.compile.spi.supplier.source.impl.AbstractSupplierSource
net.officefloor.spring.SpringSupplierSource
- All Implemented Interfaces:
SupplierSource
Spring
SupplierSource.- Author:
- Daniel Sagenschneider
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceFactory for the creation of the Spring dependencies.static interfaceSpringSupplierSource.SpringLoader<S,E extends Throwable> Provides the loading of Spring.Nested classes/interfaces inherited from class net.officefloor.compile.spi.supplier.source.impl.AbstractSupplierSource
AbstractSupplierSource.SpecificationContext -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringName ofPropertyValuefor the Spring Boot configurationClass.static final StringPropertyValueto configure active Spring profiles.static final StringPropertyValueto flag whether to unlink Spring profiles toOfficeprofiles. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <S,E extends Throwable>
ScaptureApplicationContext(Consumer<org.springframework.context.ConfigurableApplicationContext> capture, SpringSupplierSource.SpringLoader<S, E> loader) Allows capturing theConfigurableApplicationContext.static OfficeSupplierconfigure(OfficeArchitect architect, Class<?> configurationClass, String... additionalPropertyNameValuePairs) Convenience method for configuring Spring programmatically into anOffice.static org.springframework.context.ConfigurableApplicationContextforceStartSpring(AvailableType[] availableTypes) Forces starting Spring.static <O> OgetManagedObject(String qualifier, Class<? extends O> objectType) Obtains the bean fromOfficeFloor.protected voidLoads theSupplierSourceSpecification.static <S,E extends Throwable>
SrunInContext(SpringSupplierSource.SpringLoader<S, E> loader, SpringSupplierSource.SpringDependencyFactory factory) Runs theRunnablein context for theSpringSupplierSource.SpringDependencyFactoryto create additional beans for Spring.voidsupply(SupplierSourceContext context) Supplies the necessaryManagedObjectSourceinstances.voidTerminates the supply contract.Methods inherited from class net.officefloor.compile.spi.supplier.source.impl.AbstractSupplierSource
getSpecification
-
Field Details
-
PROPERTY_ACTIVE_PROFILES
PropertyValueto configure active Spring profiles.- See Also:
-
PROPERTY_UNLINK_CONTEXT_PROFILES
PropertyValueto flag whether to unlink Spring profiles toOfficeprofiles.- See Also:
-
CONFIGURATION_CLASS_NAME
Name ofPropertyValuefor the Spring Boot configurationClass.- See Also:
-
-
Constructor Details
-
SpringSupplierSource
public SpringSupplierSource()
-
-
Method Details
-
getManagedObject
Obtains the bean from
OfficeFloor.This should be used as follows:
@Configuration public class SomeConfigurationOnScanPath { @Bean public DependencyType officeFloorDependency() { return SpringSupplierSource.getManagedObject("qualifier", DependencyType.class); } }- Type Parameters:
O- Object type.- Parameters:
qualifier- Qualifier. May benull.objectType- Type of object required.- Returns:
- Object sourced from an
OfficeFloorManagedObject.
-
captureApplicationContext
public static <S,E extends Throwable> S captureApplicationContext(Consumer<org.springframework.context.ConfigurableApplicationContext> capture, SpringSupplierSource.SpringLoader<S, E> loader) throws EAllows capturing the
ConfigurableApplicationContext.Typically this is for testing to enable using Spring beans.
- Type Parameters:
S- Return type.E- Throwable type.- Parameters:
capture-Consumerto receive theConfigurableApplicationContext.loader-SpringSupplierSource.SpringLoader.- Returns:
- Loaded context.
- Throws:
E- Possible failure in loading.
-
runInContext
public static <S,E extends Throwable> S runInContext(SpringSupplierSource.SpringLoader<S, E> loader, SpringSupplierSource.SpringDependencyFactory factory) throws ERuns theRunnablein context for theSpringSupplierSource.SpringDependencyFactoryto create additional beans for Spring.- Type Parameters:
S- Loaded context.E- PossibleThrowablefrom loading.- Parameters:
loader-SpringSupplierSource.SpringLoader.factory-SpringSupplierSource.SpringDependencyFactoryto create the additional beans.- Returns:
- Loaded context.
- Throws:
E- If fails to load.
-
configure
public static OfficeSupplier configure(OfficeArchitect architect, Class<?> configurationClass, String... additionalPropertyNameValuePairs) Convenience method for configuring Spring programmatically into anOffice.- Parameters:
architect-OfficeArchitect.configurationClass- Spring Boot configurationClass.additionalPropertyNameValuePairs- AdditionalPropertyValuename/value pairs.- Returns:
OfficeSupplierfor theSpringSupplierSource.
-
forceStartSpring
public static org.springframework.context.ConfigurableApplicationContext forceStartSpring(AvailableType[] availableTypes) throws Exception Forces starting Spring.- Parameters:
availableTypes-AvailableTypeinstances.- Returns:
ConfigurableApplicationContext.nullif already started.- Throws:
Exception- If fails to start Spring.
-
loadSpecification
Description copied from class:AbstractSupplierSourceLoads theSupplierSourceSpecification.- Specified by:
loadSpecificationin classAbstractSupplierSource- Parameters:
context-AbstractSupplierSource.SpecificationContext.
-
supply
Description copied from interface:SupplierSourceSupplies the necessaryManagedObjectSourceinstances.- Parameters:
context-SupplierSourceContext.- Throws:
Exception- If fails to provide supply ofManagedObjectSourceinstances.
-
terminate
public void terminate()Description copied from interface:SupplierSourceTerminates the supply contract.
This should release all resources required by the supplier.
-