GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — Quick start Spring Quick start Spring
Dennis Kieselhorst edited this page
You can use the In the repository we have included a sample Spring application to get you started.
You can quickly create a new serverless Spring application using our Maven archetype. First, make sure Maven is installed in your environment and available in your mvn archetype:generate -DgroupId=my.service -DartifactId=my-service -Dversion=1.0-SNAPSHOT \
-DarchetypeGroupId=com.amazonaws.serverless.archetypes \
-DarchetypeArtifactId=aws-serverless-spring-archetype \
-DarchetypeVersion=2.0.1The archetype sets up a new project that includes a The project also includes a file called The first step is to import the Spring implementation of the library: <dependency> <groupId>com.amazonaws.serverless</groupId> <artifactId>aws-serverless-java-container-spring</artifactId> <version>2.0.1</version> </dependency> This will automatically also import the Dependency injection with Spring can have a significant impact on your function's cold start time. To address this, you can include the In your application package declare a new class that implements Lambda's The next step is to declare the container handler object. The library exposes a utility static method that configures a The public class StreamLambdaHandler implements RequestStreamHandler { private static SpringLambdaContainerHandler<AwsProxyRequest, AwsProxyResponse> handler; static { try { handler = SpringLambdaContainerHandler.getAwsProxyHandler(PetStoreSpringAppConfig.class); // If you are using HTTP APIs with the version 2.0 of the proxy model, use the getHttpApiV2ProxyHandler // method: handler = SpringLambdaContainerHandler.getHttpApiV2ProxyHandler(PetStoreSpringAppConfig.class); } catch (ContainerInitializationException e) { // if we fail here. We re-throw the exception to force another cold start e.printStackTrace(); throw new RuntimeException("Could not initialize Spring framework", e); } } @Override public void handleRequest(InputStream inputStream, OutputStream outputStream, Context context) throws IOException { handler.proxyStream(inputStream, outputStream, context); } } In our sample application The @Configuration @Import({ PetsController.class }) public class PetStoreSpringAppConfig { } You can follow the instructions in AWS Lambda's documentation on how to package your function for deployment. Spring applications can be slow to start, particularly if they discover and initialize a lot of components. In the example above, we recommend using a static block or the constructor of your The asynchronous initializer retrieves the JVM startup time to estimate how much time has already elapsed since AWS Lambda created the handler. The asynchronous initializer will start our Spring application context in a separate thread and return control back to AWS Lambda just before the 10 seconds timeout expires. Obviously, if your application takes less than 10 seconds to start we will return control back to AWS Lambda right away. When Lambda sends the first event, Serverless Java Container will wait for the asynchronous initializer to complete its work before sending the event for processing. By default, Serverless Java Container will wait for an additional 10 seconds. You can change this using the There are two ways to activate Spring Profiles (as defined with the public class StreamLambdaHandler implements RequestStreamHandler { private static SpringLambdaContainerHandler<AwsProxyRequest, AwsProxyResponse> handler; static { try { AnnotationConfigWebApplicationContext applicationContext = new AnnotationConfigWebApplicationContext(); applicationContext.register(PetStoreSpringAppConfig.class); handler = SpringLambdaContainerHandler.getAwsProxyHandler(applicationContext, "profile-1", "profile-2"); } catch (ContainerInitializationException e) { // if we fail here. We re-throw the exception to force another cold start e.printStackTrace(); throw new RuntimeException("Could not initialize Spring framework", e); } } ... } If you need to reload profiles at runtime, you can use the The Spring archetypes and samples include a Spring relies heavily on introspection to discover resources, beans, and wire your application together. Introspection can be CPU-intensive and contributes to the cold start time of a Java application. There are a number of optimization we can make in our Spring application to minimize cold start times in Lambda. In our examples above, the private static SpringLambdaContainerHandler<AwsProxyRequest, AwsProxyResponse> handler; static { try { handler = SpringLambdaContainerHandler.getAwsProxyHandler(PetStoreSpringAppConfig.class); } catch (ContainerInitializationException e) { // if we fail here. We re-throw the exception to force another cold start e.printStackTrace(); throw new RuntimeException("Could not initialize Spring framework", e); } } The Spring @Configuration @Import({ PetsController.class }) public class PetStoreSpringAppConfig { ... } Starting the The Spring container can automatically wire relationships between collaboration beans using introspection of the bean classes. This eliminates the need to explicitly specify the relationships as properties or constructor arguments within the application configuration metadata. Instead, use the To associate parameter names with their respective bean, Spring requires the to be compiled with the debug flag enabled. Spring caches the relationship on disk, which causes significant I/O time penalty. Use the public class Pet { @ConstructorProperties({"name", "breed"}) public Pet(String name, String breed) { this.name = name; this.breed = synopsis; } } Clone this wiki locally |
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |