Fix conditions for custom AWS runtime
Conflicts: spring-cloud-function-samples/function-sample-aws-custom/pom.xml
This commit is contained in:
committed by
Oleg Zhurakousky
parent
1de8526b7a
commit
5e3111bf80
@@ -32,7 +32,7 @@ import org.springframework.context.annotation.Configuration;
|
||||
@Configuration
|
||||
@AutoConfigureBefore(FunctionExporterAutoConfiguration.class)
|
||||
@ConditionalOnClass(DestinationResolver.class)
|
||||
@ConditionalOnProperty(prefix = "spring.cloud.function.web.export", name = "enabled", matchIfMissing = true)
|
||||
@ConditionalOnProperty(prefix = "spring.cloud.function.web.export", name = "enabled", matchIfMissing = false)
|
||||
public class CustomRuntimeAutoConfiguration {
|
||||
|
||||
@Bean
|
||||
|
||||
@@ -27,25 +27,21 @@ import org.springframework.core.annotation.Order;
|
||||
* @author Dave Syer
|
||||
*/
|
||||
@Order(0)
|
||||
public class CustomRuntimeInitializer
|
||||
implements ApplicationContextInitializer<GenericApplicationContext> {
|
||||
public class CustomRuntimeInitializer implements ApplicationContextInitializer<GenericApplicationContext> {
|
||||
|
||||
@Override
|
||||
public void initialize(GenericApplicationContext context) {
|
||||
Boolean enabled = context.getEnvironment()
|
||||
.getProperty("spring.cloud.function.web.export.enabled", Boolean.class);
|
||||
if (enabled != null) {
|
||||
Boolean enabled = context.getEnvironment().getProperty("spring.cloud.function.web.export.enabled",
|
||||
Boolean.class);
|
||||
if (enabled == null || !enabled) {
|
||||
return;
|
||||
}
|
||||
if (ContextFunctionCatalogInitializer.enabled && context.getEnvironment()
|
||||
.getProperty("spring.functional.enabled", Boolean.class, false)) {
|
||||
if (context.getBeanFactory().getBeanNamesForType(DestinationResolver.class,
|
||||
false, false).length == 0) {
|
||||
context.registerBean(LambdaDestinationResolver.class,
|
||||
() -> new LambdaDestinationResolver());
|
||||
if (ContextFunctionCatalogInitializer.enabled
|
||||
&& context.getEnvironment().getProperty("spring.functional.enabled", Boolean.class, false)) {
|
||||
if (context.getBeanFactory().getBeanNamesForType(DestinationResolver.class, false, false).length == 0) {
|
||||
context.registerBean(LambdaDestinationResolver.class, () -> new LambdaDestinationResolver());
|
||||
}
|
||||
context.registerBean(CommandLineRunner.class,
|
||||
() -> args -> CustomRuntimeAutoConfiguration.background());
|
||||
context.registerBean(CommandLineRunner.class, () -> args -> CustomRuntimeAutoConfiguration.background());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -10,14 +10,14 @@
|
||||
</parent>
|
||||
<groupId>io.spring.sample</groupId>
|
||||
<artifactId>function-sample-aws-custom</artifactId>
|
||||
<version>2.0.0.RELEASE</version>
|
||||
<version>3.0.0.RELEASE</version>
|
||||
<name>lambda</name>
|
||||
<description>Demo project for Spring Cloud Function with custom AWS Lambda runtime</description>
|
||||
|
||||
<properties>
|
||||
<java.version>1.8</java.version>
|
||||
<wrapper.version>1.0.21.RELEASE</wrapper.version>
|
||||
<spring-cloud-function.version>2.2.0.BUILD-SNAPSHOT</spring-cloud-function.version>
|
||||
<wrapper.version>1.0.22.RELEASE</wrapper.version>
|
||||
<spring-cloud-function.version>3.0.0.BUILD-SNAPSHOT</spring-cloud-function.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
@@ -120,11 +120,6 @@
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<archive>
|
||||
<manifest>
|
||||
<mainClass>com.sample.App</mainClass>
|
||||
</manifest>
|
||||
</archive>
|
||||
<descriptors>
|
||||
<descriptor>src/assembly/zip.xml</descriptor>
|
||||
</descriptors>
|
||||
|
||||
@@ -33,13 +33,12 @@ import org.springframework.web.reactive.function.client.WebClient;
|
||||
* @since 2.0
|
||||
*
|
||||
*/
|
||||
class FunctionExporterInitializer
|
||||
implements ApplicationContextInitializer<GenericApplicationContext> {
|
||||
class FunctionExporterInitializer implements ApplicationContextInitializer<GenericApplicationContext> {
|
||||
|
||||
@Override
|
||||
public void initialize(GenericApplicationContext context) {
|
||||
if (ContextFunctionCatalogInitializer.enabled && context.getEnvironment()
|
||||
.getProperty("spring.functional.enabled", Boolean.class, false)
|
||||
if (ContextFunctionCatalogInitializer.enabled
|
||||
&& context.getEnvironment().getProperty("spring.functional.enabled", Boolean.class, false)
|
||||
&& isExporting(context)) {
|
||||
registerWebClient(context);
|
||||
registerExport(context);
|
||||
@@ -47,25 +46,22 @@ class FunctionExporterInitializer
|
||||
}
|
||||
|
||||
private void registerWebClient(GenericApplicationContext context) {
|
||||
if (context.getBeanFactory().getBeanNamesForType(WebClient.Builder.class, false,
|
||||
false).length == 0) {
|
||||
if (context.getBeanFactory().getBeanNamesForType(WebClient.Builder.class, false, false).length == 0) {
|
||||
context.registerBean(WebClient.Builder.class, () -> WebClient.builder());
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isExporting(GenericApplicationContext context) {
|
||||
Boolean enabled = context.getEnvironment()
|
||||
.getProperty("spring.cloud.function.web.export.enabled", Boolean.class);
|
||||
Boolean enabled = context.getEnvironment().getProperty("spring.cloud.function.web.export.enabled",
|
||||
Boolean.class);
|
||||
if (enabled != null) {
|
||||
return enabled;
|
||||
}
|
||||
if (ClassUtils.isPresent("org.springframework.web.context.WebApplicationContext",
|
||||
getClass().getClassLoader())) {
|
||||
if (context instanceof WebApplicationContext
|
||||
|| context instanceof ReactiveWebApplicationContext
|
||||
if (context instanceof WebApplicationContext || context instanceof ReactiveWebApplicationContext
|
||||
|| context.getEnvironment() instanceof ConfigurableWebEnvironment
|
||||
|| context
|
||||
.getEnvironment() instanceof ConfigurableReactiveWebEnvironment) {
|
||||
|| context.getEnvironment() instanceof ConfigurableReactiveWebEnvironment) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -75,34 +71,24 @@ class FunctionExporterInitializer
|
||||
private void registerExport(GenericApplicationContext context) {
|
||||
context.registerBean(ExporterProperties.class, () -> new ExporterProperties());
|
||||
context.registerBean(FunctionExporterAutoConfiguration.class,
|
||||
() -> new FunctionExporterAutoConfiguration(
|
||||
context.getBean(ExporterProperties.class)));
|
||||
if (context.getBeanFactory().getBeanNamesForType(DestinationResolver.class, false,
|
||||
false).length == 0) {
|
||||
() -> new FunctionExporterAutoConfiguration(context.getBean(ExporterProperties.class)));
|
||||
if (context.getBeanFactory().getBeanNamesForType(DestinationResolver.class, false, false).length == 0) {
|
||||
context.registerBean(DestinationResolver.class,
|
||||
() -> context.getBean(FunctionExporterAutoConfiguration.class)
|
||||
.simpleDestinationResolver());
|
||||
() -> context.getBean(FunctionExporterAutoConfiguration.class).simpleDestinationResolver());
|
||||
}
|
||||
if (context.getBeanFactory().getBeanNamesForType(RequestBuilder.class, false,
|
||||
false).length == 0) {
|
||||
context.registerBean(RequestBuilder.class,
|
||||
() -> context.getBean(FunctionExporterAutoConfiguration.class)
|
||||
.simpleRequestBuilder(context.getEnvironment()));
|
||||
if (context.getBeanFactory().getBeanNamesForType(RequestBuilder.class, false, false).length == 0) {
|
||||
context.registerBean(RequestBuilder.class, () -> context.getBean(FunctionExporterAutoConfiguration.class)
|
||||
.simpleRequestBuilder(context.getEnvironment()));
|
||||
}
|
||||
if (context.getEnvironment()
|
||||
.getProperty("spring.cloud.function.web.export.source.url") != null) {
|
||||
context.registerBean("origin", FunctionRegistration.class,
|
||||
() -> context.getBean(FunctionExporterAutoConfiguration.class)
|
||||
.origin(context.getBean(WebClient.Builder.class)));
|
||||
if (context.getEnvironment().getProperty("spring.cloud.function.web.export.source.url") != null) {
|
||||
context.registerBean("origin", FunctionRegistration.class, () -> context
|
||||
.getBean(FunctionExporterAutoConfiguration.class).origin(context.getBean(WebClient.Builder.class)));
|
||||
}
|
||||
if (context.getEnvironment()
|
||||
.getProperty("spring.cloud.function.web.export.sink.url") != null) {
|
||||
if (context.getEnvironment().getProperty("spring.cloud.function.web.export.sink.url") != null) {
|
||||
context.registerBean(SupplierExporter.class,
|
||||
() -> context.getBean(FunctionExporterAutoConfiguration.class)
|
||||
.sourceForwarder(context.getBean(RequestBuilder.class),
|
||||
context.getBean(DestinationResolver.class),
|
||||
context.getBean(FunctionCatalog.class),
|
||||
context.getBean(WebClient.Builder.class)));
|
||||
() -> context.getBean(FunctionExporterAutoConfiguration.class).sourceForwarder(
|
||||
context.getBean(RequestBuilder.class), context.getBean(DestinationResolver.class),
|
||||
context.getBean(FunctionCatalog.class), context.getBean(WebClient.Builder.class)));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user