Add support for ApplicationContextInitializer in azure adapter
This commit is contained in:
8
pom.xml
8
pom.xml
@@ -18,7 +18,6 @@
|
|||||||
<java.version>1.8</java.version>
|
<java.version>1.8</java.version>
|
||||||
<spring-cloud-task.version>2.0.0.RELEASE</spring-cloud-task.version>
|
<spring-cloud-task.version>2.0.0.RELEASE</spring-cloud-task.version>
|
||||||
<wrapper.version>1.0.15.RELEASE</wrapper.version>
|
<wrapper.version>1.0.15.RELEASE</wrapper.version>
|
||||||
<spring-boot.version>2.1.0.M1</spring-boot.version>
|
|
||||||
<docs.main>spring-cloud-function</docs.main>
|
<docs.main>spring-cloud-function</docs.main>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
@@ -38,13 +37,6 @@
|
|||||||
<type>pom</type>
|
<type>pom</type>
|
||||||
<scope>import</scope>
|
<scope>import</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>org.springframework.boot</groupId>
|
|
||||||
<artifactId>spring-boot-dependencies</artifactId>
|
|
||||||
<version>${spring-boot.version}</version>
|
|
||||||
<type>pom</type>
|
|
||||||
<scope>import</scope>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</dependencyManagement>
|
</dependencyManagement>
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
<artifactId>spring-cloud-function-adapter-azure</artifactId>
|
<artifactId>spring-cloud-function-adapter-azure</artifactId>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<name>spring-cloud-function-adapter-aws</name>
|
<name>spring-cloud-function-adapter-azure</name>
|
||||||
<description>Azure Function Adapter for Spring Cloud Function</description>
|
<description>Azure Function Adapter for Spring Cloud Function</description>
|
||||||
|
|
||||||
<parent>
|
<parent>
|
||||||
|
|||||||
@@ -97,7 +97,7 @@ public class AzureSpringFunctionInitializer implements Closeable {
|
|||||||
if (context == null) {
|
if (context == null) {
|
||||||
ClassUtils.overrideThreadContextClassLoader(
|
ClassUtils.overrideThreadContextClassLoader(
|
||||||
AzureSpringFunctionInitializer.class.getClassLoader());
|
AzureSpringFunctionInitializer.class.getClassLoader());
|
||||||
springApplication().run();
|
context = springApplication().run();
|
||||||
AzureSpringFunctionInitializer.context = context;
|
AzureSpringFunctionInitializer.context = context;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,7 +26,6 @@ import org.springframework.beans.factory.config.BeanPostProcessor;
|
|||||||
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
|
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
|
||||||
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
|
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
|
||||||
import org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor;
|
import org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor;
|
||||||
import org.springframework.boot.autoconfigure.BackgroundPreinitializer;
|
|
||||||
import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration;
|
import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration;
|
||||||
import org.springframework.boot.context.properties.ConfigurationBeanFactoryMetadata;
|
import org.springframework.boot.context.properties.ConfigurationBeanFactoryMetadata;
|
||||||
import org.springframework.boot.context.properties.ConfigurationPropertiesBindingPostProcessor;
|
import org.springframework.boot.context.properties.ConfigurationPropertiesBindingPostProcessor;
|
||||||
@@ -50,6 +49,8 @@ import org.springframework.util.ClassUtils;
|
|||||||
public class ContextFunctionCatalogInitializer
|
public class ContextFunctionCatalogInitializer
|
||||||
implements ApplicationContextInitializer<GenericApplicationContext> {
|
implements ApplicationContextInitializer<GenericApplicationContext> {
|
||||||
|
|
||||||
|
public static final String IGNORE_BACKGROUNDPREINITIALIZER_PROPERTY_NAME = "spring.backgroundpreinitializer.ignore";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void initialize(GenericApplicationContext applicationContext) {
|
public void initialize(GenericApplicationContext applicationContext) {
|
||||||
if (applicationContext.getEnvironment().getProperty("spring.functional.enabled",
|
if (applicationContext.getEnvironment().getProperty("spring.functional.enabled",
|
||||||
@@ -97,20 +98,20 @@ public class ContextFunctionCatalogInitializer
|
|||||||
|
|
||||||
performPreinitialization();
|
performPreinitialization();
|
||||||
|
|
||||||
if (context.getBeanNamesForType(PropertySourcesPlaceholderConfigurer.class,
|
if (context.getBeanFactory().getBeanNamesForType(PropertySourcesPlaceholderConfigurer.class,
|
||||||
false, false).length == 0) {
|
false, false).length == 0) {
|
||||||
context.registerBean(PropertySourcesPlaceholderConfigurer.class,
|
context.registerBean(PropertySourcesPlaceholderConfigurer.class,
|
||||||
() -> PropertyPlaceholderAutoConfiguration
|
() -> PropertyPlaceholderAutoConfiguration
|
||||||
.propertySourcesPlaceholderConfigurer());
|
.propertySourcesPlaceholderConfigurer());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!context.containsBean(
|
if (!context.getBeanFactory().containsBean(
|
||||||
AnnotationConfigUtils.AUTOWIRED_ANNOTATION_PROCESSOR_BEAN_NAME)) {
|
AnnotationConfigUtils.AUTOWIRED_ANNOTATION_PROCESSOR_BEAN_NAME)) {
|
||||||
context.registerBean(
|
context.registerBean(
|
||||||
AnnotationConfigUtils.AUTOWIRED_ANNOTATION_PROCESSOR_BEAN_NAME,
|
AnnotationConfigUtils.AUTOWIRED_ANNOTATION_PROCESSOR_BEAN_NAME,
|
||||||
AutowiredAnnotationBeanPostProcessor.class);
|
AutowiredAnnotationBeanPostProcessor.class);
|
||||||
}
|
}
|
||||||
if (!context.containsBean(ConfigurationBeanFactoryMetadata.BEAN_NAME)) {
|
if (!context.getBeanFactory().containsBean(ConfigurationBeanFactoryMetadata.BEAN_NAME)) {
|
||||||
context.registerBean(ConfigurationBeanFactoryMetadata.BEAN_NAME,
|
context.registerBean(ConfigurationBeanFactoryMetadata.BEAN_NAME,
|
||||||
ConfigurationBeanFactoryMetadata.class,
|
ConfigurationBeanFactoryMetadata.class,
|
||||||
() -> new ConfigurationBeanFactoryMetadata());
|
() -> new ConfigurationBeanFactoryMetadata());
|
||||||
@@ -124,7 +125,7 @@ public class ContextFunctionCatalogInitializer
|
|||||||
&& !"gson".equals(context.getEnvironment().getProperty(
|
&& !"gson".equals(context.getEnvironment().getProperty(
|
||||||
ContextFunctionCatalogAutoConfiguration.PREFERRED_MAPPER_PROPERTY,
|
ContextFunctionCatalogAutoConfiguration.PREFERRED_MAPPER_PROPERTY,
|
||||||
"gson"))) {
|
"gson"))) {
|
||||||
if (context.getBeanNamesForType(Gson.class, false, false).length == 0) {
|
if (context.getBeanFactory().getBeanNamesForType(Gson.class, false, false).length == 0) {
|
||||||
context.registerBean(Gson.class, () -> new Gson());
|
context.registerBean(Gson.class, () -> new Gson());
|
||||||
}
|
}
|
||||||
context.registerBean(JsonMapper.class,
|
context.registerBean(JsonMapper.class,
|
||||||
@@ -132,8 +133,8 @@ public class ContextFunctionCatalogInitializer
|
|||||||
.jsonMapper(context.getBean(Gson.class)));
|
.jsonMapper(context.getBean(Gson.class)));
|
||||||
}
|
}
|
||||||
else if (ClassUtils.isPresent(
|
else if (ClassUtils.isPresent(
|
||||||
"com.fasterxml.jackson.databind.ObjectMapper.ObjectMapper", null)) {
|
"com.fasterxml.jackson.databind.ObjectMapper", null)) {
|
||||||
if (context.getBeanNamesForType(ObjectMapper.class, false,
|
if (context.getBeanFactory().getBeanNamesForType(ObjectMapper.class, false,
|
||||||
false).length == 0) {
|
false).length == 0) {
|
||||||
context.registerBean(ObjectMapper.class, () -> new ObjectMapper());
|
context.registerBean(ObjectMapper.class, () -> new ObjectMapper());
|
||||||
}
|
}
|
||||||
@@ -143,7 +144,7 @@ public class ContextFunctionCatalogInitializer
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (context.getBeanNamesForType(FunctionCatalog.class, false,
|
if (context.getBeanFactory().getBeanNamesForType(FunctionCatalog.class, false,
|
||||||
false).length == 0) {
|
false).length == 0) {
|
||||||
context.registerBean(InMemoryFunctionCatalog.class,
|
context.registerBean(InMemoryFunctionCatalog.class,
|
||||||
() -> new InMemoryFunctionCatalog());
|
() -> new InMemoryFunctionCatalog());
|
||||||
@@ -154,7 +155,7 @@ public class ContextFunctionCatalogInitializer
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void performPreinitialization() {
|
private void performPreinitialization() {
|
||||||
if (Boolean.getBoolean(BackgroundPreinitializer.IGNORE_BACKGROUNDPREINITIALIZER_PROPERTY_NAME)) {
|
if (Boolean.getBoolean(IGNORE_BACKGROUNDPREINITIALIZER_PROPERTY_NAME)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
|
|||||||
Reference in New Issue
Block a user