Skip to content

Commit fc469d1

Browse files
committed
Added Spring Boot sample in the readme
1 parent 1da7013 commit fc469d1

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,25 @@ public class LambdaHandler implements RequestHandler<AwsProxyRequest, AwsProxyRe
6262
#### Spring Profiles
6363
You can enable Spring Profiles (as defined with the `@Profile` annotation) by using the `SpringLambdaContainerHandler.activateSpringProfiles(String...)` method - common drivers of this might be the AWS Lambda stage that you're deployed under, or stage variables. See [@Profile documentation](http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/context/annotation/Profile.html) for details.
6464

65+
#### Spring Boot
66+
You can also use this framework to start Spring Boot applications inside Lambda. The framework does not recognize classes annotated with `@SpringBootApplication` automatically. However, you can wrap the Spring Boot application class in a regular `ConfigurableWebApplicationContext` object. In your handler class, instead of initializing the `SpringLambdaContainerHandler` with the Spring Boot application class, initialize another context and set the Spring Boot app as a parent:
67+
68+
```java
69+
SpringApplication springBootApplication = new SpringApplication(SpringBootApplication.class);
70+
springBootApplication.setWebEnvironment(false);
71+
springBootApplication.setBannerMode(Banner.Mode.OFF);
72+
73+
// create a new empty context and set the spring boot application as a parent of it
74+
ConfigurableWebApplicationContext wrappingContext = new AnnotationConfigWebApplicationContext();
75+
wrappingContext.setParent(springBootApplication.run());
76+
77+
// now we can initialize the framework with the wrapping context
78+
SpringLambdaContainerHandler<AwsProxyRequest, AwsProxyResponse> handler =
79+
SpringLambdaContainerHandler.getAwsProxyHandler(wrappingContext);
80+
```
81+
82+
When using Spring Boot, make sure to configure the shade plugin in your pom file to exclude the embedded container and all unnecessary libraries to reduce the size of your built jar.
83+
6584
### Spark support
6685
The library also supports applications written with the [Spark framework](http://sparkjava.com/). When using the library with Spark, it's important to initialize the `SparkLambdaContainerHandler` before defining routes.
6786

0 commit comments

Comments
 (0)