Skip to content

Commit 1395424

Browse files
committed
GH-1030 Add property for late initialization of AC
Resolves #1030
1 parent 53b61e5 commit 1395424

File tree

1 file changed

+13
-1
lines changed
  • spring-cloud-function-adapters/spring-cloud-function-adapter-aws/src/main/java/org/springframework/cloud/function/adapter/aws

1 file changed

+13
-1
lines changed

spring-cloud-function-adapters/spring-cloud-function-adapter-aws/src/main/java/org/springframework/cloud/function/adapter/aws/FunctionInvoker.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,17 @@ public class FunctionInvoker implements RequestStreamHandler {
6262

6363
private volatile String functionDefinition;
6464

65+
private boolean started;
66+
6567
public FunctionInvoker(String functionDefinition) {
6668
this.functionDefinition = functionDefinition;
67-
this.start();
69+
String lateInitialization = System.getenv("FUNCTION_INVOKER_LATE_INITIALIZATION");
70+
if (!StringUtils.hasText(lateInitialization) || !Boolean.parseBoolean(lateInitialization)) {
71+
this.start();
72+
}
73+
else {
74+
logger.info("Spring Application Context will be initialized on first request");
75+
}
6876
}
6977

7078
public FunctionInvoker() {
@@ -74,6 +82,9 @@ public FunctionInvoker() {
7482
@SuppressWarnings({ "rawtypes" })
7583
@Override
7684
public void handleRequest(InputStream input, OutputStream output, Context context) throws IOException {
85+
if (!this.started) {
86+
this.start();
87+
}
7788
Message requestMessage = AWSLambdaUtils
7889
.generateMessage(input, this.function.getInputType(), this.function.isSupplier(), jsonMapper, context);
7990

@@ -142,5 +153,6 @@ private void start() {
142153
if (logger.isInfoEnabled()) {
143154
logger.info("Located function: '" + this.functionDefinition + "'");
144155
}
156+
this.started = true;
145157
}
146158
}

0 commit comments

Comments
 (0)