Package energy.eddie.spring
Class RegionConnectorRegistrationBeanPostProcessor
java.lang.Object
energy.eddie.spring.RegionConnectorRegistrationBeanPostProcessor
- All Implemented Interfaces:
org.springframework.beans.factory.config.BeanFactoryPostProcessor,org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor,org.springframework.core.Ordered
public class RegionConnectorRegistrationBeanPostProcessor
extends Object
implements org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor, org.springframework.core.Ordered
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringName of the Bean registered in the core context that holds a list of the IDs of the enabled region connectors.static final Stringstatic final StringBase package under which all region connectors are located.Fields inherited from interface org.springframework.core.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE -
Constructor Summary
ConstructorsConstructorDescriptionRegionConnectorRegistrationBeanPostProcessor(org.springframework.core.env.Environment environment) -
Method Summary
Modifier and TypeMethodDescriptionstatic Class<?> classForBeanDefinition(org.springframework.beans.factory.config.BeanDefinition definition) static voidenableSpringDoc(org.springframework.web.context.support.AnnotationConfigWebApplicationContext applicationContext) Enables SpringDoc OpenAPI in the specifiedapplicationContextby in registering the necessary Spring and Swagger Beans.intgetOrder()Run this processor as the last one.voidpostProcessBeanDefinitionRegistry(org.springframework.beans.factory.support.BeanDefinitionRegistry registry) Scans the "energy.eddie.regionconnector" package for any classes that are annotated withRegionConnectorand creates a separate context andDispatcherServletfor each found class, which will be registered with the registry passed to this processor.voidpostProcessBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory unusedBeanFactory)
-
Field Details
-
ENABLED_REGION_CONNECTOR_BEAN_NAME
Name of the Bean registered in the core context that holds a list of the IDs of the enabled region connectors.- See Also:
-
REGION_CONNECTORS_SCAN_BASE_PACKAGE
Base package under which all region connectors are located.- See Also:
-
OUTBOUND_CONNECTORS_SCAN_BASE_PACKAGE
- See Also:
-
-
Constructor Details
-
RegionConnectorRegistrationBeanPostProcessor
public RegionConnectorRegistrationBeanPostProcessor(org.springframework.core.env.Environment environment)
-
-
Method Details
-
classForBeanDefinition
public static Class<?> classForBeanDefinition(org.springframework.beans.factory.config.BeanDefinition definition) -
enableSpringDoc
public static void enableSpringDoc(org.springframework.web.context.support.AnnotationConfigWebApplicationContext applicationContext) Enables SpringDoc OpenAPI in the specifiedapplicationContextby in registering the necessary Spring and Swagger Beans. The documentation will be available at theurlMappingof the context's dispatcher servlet, e.g. "/region-connectors/dk-energinet/v3/api-docs".- Parameters:
applicationContext- Context for which to enable the SpringDoc support.
-
postProcessBeanDefinitionRegistry
public void postProcessBeanDefinitionRegistry(@NonNull org.springframework.beans.factory.support.BeanDefinitionRegistry registry) throws InitializationException Scans the "energy.eddie.regionconnector" package for any classes that are annotated withRegionConnectorand creates a separate context andDispatcherServletfor each found class, which will be registered with the registry passed to this processor.Important: Only region connectors that have their property region-connector.RC-NAME.enabled explicitly set to true are loaded.
The DispatcherServlet has its URL mapping set to "/"region-connectors"/{RC-NAME}/*" whereas
RC-NAMEis specified byRegionConnector.name().- Specified by:
postProcessBeanDefinitionRegistryin interfaceorg.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor- Parameters:
registry- the bean definition registry used by the application context- Throws:
InitializationException- If no region connector has been enabled in theapplication.propertiesfile or any other unexpected initialization error occurs.
-
postProcessBeanFactory
public void postProcessBeanFactory(@NonNull org.springframework.beans.factory.config.ConfigurableListableBeanFactory unusedBeanFactory) throws org.springframework.beans.BeansException - Specified by:
postProcessBeanFactoryin interfaceorg.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor- Specified by:
postProcessBeanFactoryin interfaceorg.springframework.beans.factory.config.BeanFactoryPostProcessor- Throws:
org.springframework.beans.BeansException
-
getOrder
public int getOrder()Run this processor as the last one. Spring documentation recommends to implementOrderedinterface for bean post processors.- Specified by:
getOrderin interfaceorg.springframework.core.Ordered- Returns:
- Integer.MAX_VALUE
-