Beliebte Suchanfragen

Cloud Native

DevOps

IT-Security

Agile Methoden

Java

//

Deploying Spring Boot Applications in the Google AppEngine Flex Environment

13.2.2018 | 2 minutes of reading time

In this tutorial I will show how to set up a deployment of Spring Boot applications for the AppEngine Flex environment in the Google Cloud infrastructure.

Prerequisites

You should be familiar with the Spring Boot ecosystem and should be able to use Maven as a build tool.

Preparations for Google AppEngine Development

There are several general steps to go through in order to be able to deploy an application to the AppEngine environment.

  • Create a Google Cloud account and set up billing.
  • Create a new project . Accept the proposed project ID or choose your own. We will use the expression [PROJECT_ID] for the rest of this tutorial.
  • Download and install the GCP Cloud SDK .
  • Initialize the Cloud SDK so it points to your GCP project:
1gcloud init [PROJECT_ID]

Spring Boot Demo Application

With the new AppEngine Flex Environment you are no longer restricted to the Jetty web framework in order to run web applications. So there is no need to tweak your Spring Boot dependencies in order to run in the GAE any more. (Check the differences between the standard and the flex environment .)

Our first Spring Boot application will feature a very simple REST controller:

1@RestController
2public class HelloController {
3 
4    @RequestMapping("/hello")
5    public String hello() { return "Hello AppEngine Flex"; }
6}

Since the AppEngine performs a health check by default, we are using the actuator starter and bind it to the required path in src/main/resources/application.yml:

1management:
2   context-path: /_ah
3   security:
4    enabled: false

For the sake of simplicity we are using the GAE legacy health check that will perform a GET request to /_ah/health.

AppEngine Flex Deployment

The AppEngine deployment descriptor has to be located in src/main/appengine/app.yaml. These are the most important settings:

1service: sb-gcp # Id of the service
2env: flex       # Flex environment
3runtime: java   # Java runtime
4runtime_config:
5  jdk: openjdk8 # use OpenJDK 8
6...

Your project holds several services . Each service needs a unique identifier that is set by the service parameter. Then we configure the flex environment and the Java runtime.

In order to deploy the Spring Boot application, we are using this Maven plugin:

1<!-- AppEngine -->
2<plugin>
3  <groupId>com.google.cloud.tools</groupId>
4  <artifactId>appengine-maven-plugin</artifactId>
5  <version>1.3.2</version>
6  <configuration>
7    <project>[PROJECT_ID]</project>
8  </configuration>
9</plugin>

Now we are ready to build a deployment:

1mvn clean package appengine:deploy

The last Maven goal triggers the deployment which in the end is performed by the gcloud command line client from the Cloud SDK. This will run for some time. Basically, a Docker image containing your Spring Boot JAR is built and deployed to the GCP. After deploymemt is finally finished, your application will show up in the

AppEngine Dashboard

Each deployment creates a new version of a service. Our AppEngine dashboard for the service named sb-gcp may look like this:

You can start and stop your service, go back to older versions etc.

And finally we see our running application at

1https://sb-gcp-dot-[PROJECT_ID].appspot.com

That’s the output from our simple REST controller:

1curl https://sb-gcp-dot-[PROJECT_ID].appspot.com/hello
2Hello AppEngine Flex

What’s next?

In upcoming posts I’ll show you how to access backends in the Google Compute Engine from Spring Boot applications.

share post

Likes

0

//

More articles in this subject area

Discover exciting further topics and let the codecentric world inspire you.

//

Gemeinsam bessere Projekte umsetzen.

Wir helfen deinem Unternehmen.

Du stehst vor einer großen IT-Herausforderung? Wir sorgen für eine maßgeschneiderte Unterstützung. Informiere dich jetzt.

Hilf uns, noch besser zu werden.

Wir sind immer auf der Suche nach neuen Talenten. Auch für dich ist die passende Stelle dabei.