Add support for ApplicationContextInitializer in azure adapter

This commit is contained in:
Dave Syer
2018-10-02 12:52:23 +01:00
parent bb1c97251f
commit 37729e4583
4 changed files with 12 additions and 19 deletions

View File

@@ -18,7 +18,6 @@
<java.version>1.8</java.version>
<spring-cloud-task.version>2.0.0.RELEASE</spring-cloud-task.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>
</properties>
@@ -38,13 +37,6 @@
<type>pom</type>
<scope>import</scope>
</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>
</dependencyManagement>

View File

@@ -7,7 +7,7 @@
<artifactId>spring-cloud-function-adapter-azure</artifactId>
<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>
<parent>

View File

@@ -97,7 +97,7 @@ public class AzureSpringFunctionInitializer implements Closeable {
if (context == null) {
ClassUtils.overrideThreadContextClassLoader(
AzureSpringFunctionInitializer.class.getClassLoader());
springApplication().run();
context = springApplication().run();
AzureSpringFunctionInitializer.context = context;
}
}

View File

@@ -26,7 +26,6 @@ import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor;
import org.springframework.boot.autoconfigure.BackgroundPreinitializer;
import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration;
import org.springframework.boot.context.properties.ConfigurationBeanFactoryMetadata;
import org.springframework.boot.context.properties.ConfigurationPropertiesBindingPostProcessor;
@@ -50,6 +49,8 @@ import org.springframework.util.ClassUtils;
public class ContextFunctionCatalogInitializer
implements ApplicationContextInitializer<GenericApplicationContext> {
public static final String IGNORE_BACKGROUNDPREINITIALIZER_PROPERTY_NAME = "spring.backgroundpreinitializer.ignore";
@Override
public void initialize(GenericApplicationContext applicationContext) {
if (applicationContext.getEnvironment().getProperty("spring.functional.enabled",
@@ -97,20 +98,20 @@ public class ContextFunctionCatalogInitializer
performPreinitialization();
if (context.getBeanNamesForType(PropertySourcesPlaceholderConfigurer.class,
if (context.getBeanFactory().getBeanNamesForType(PropertySourcesPlaceholderConfigurer.class,
false, false).length == 0) {
context.registerBean(PropertySourcesPlaceholderConfigurer.class,
() -> PropertyPlaceholderAutoConfiguration
.propertySourcesPlaceholderConfigurer());
}
if (!context.containsBean(
if (!context.getBeanFactory().containsBean(
AnnotationConfigUtils.AUTOWIRED_ANNOTATION_PROCESSOR_BEAN_NAME)) {
context.registerBean(
AnnotationConfigUtils.AUTOWIRED_ANNOTATION_PROCESSOR_BEAN_NAME,
AutowiredAnnotationBeanPostProcessor.class);
}
if (!context.containsBean(ConfigurationBeanFactoryMetadata.BEAN_NAME)) {
if (!context.getBeanFactory().containsBean(ConfigurationBeanFactoryMetadata.BEAN_NAME)) {
context.registerBean(ConfigurationBeanFactoryMetadata.BEAN_NAME,
ConfigurationBeanFactoryMetadata.class,
() -> new ConfigurationBeanFactoryMetadata());
@@ -124,7 +125,7 @@ public class ContextFunctionCatalogInitializer
&& !"gson".equals(context.getEnvironment().getProperty(
ContextFunctionCatalogAutoConfiguration.PREFERRED_MAPPER_PROPERTY,
"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(JsonMapper.class,
@@ -132,8 +133,8 @@ public class ContextFunctionCatalogInitializer
.jsonMapper(context.getBean(Gson.class)));
}
else if (ClassUtils.isPresent(
"com.fasterxml.jackson.databind.ObjectMapper.ObjectMapper", null)) {
if (context.getBeanNamesForType(ObjectMapper.class, false,
"com.fasterxml.jackson.databind.ObjectMapper", null)) {
if (context.getBeanFactory().getBeanNamesForType(ObjectMapper.class, false,
false).length == 0) {
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) {
context.registerBean(InMemoryFunctionCatalog.class,
() -> new InMemoryFunctionCatalog());
@@ -154,7 +155,7 @@ public class ContextFunctionCatalogInitializer
}
private void performPreinitialization() {
if (Boolean.getBoolean(BackgroundPreinitializer.IGNORE_BACKGROUNDPREINITIALIZER_PROPERTY_NAME)) {
if (Boolean.getBoolean(IGNORE_BACKGROUNDPREINITIALIZER_PROPERTY_NAME)) {
return;
}
try {