I tried Java8 + Spring Boot with GAE SE (and about its development environment)

I tried Java8 + Spring Boot on GAE Java. Basically, I should just do the official website, but I was addicted to the development environment, so I made a note. Or rather, the official documentation was quite disjointed and I wasn't sure which one to refer to, so it was hard.

This time, based on this Using Apache Maven and the App Engine Plugin, [GitHub Repository](https: / I made it while borrowing the contents from /github.com/GoogleCloudPlatform/getting-started-java/tree/master/appengine-standard-java8/springboot-appengine-standard).

If you make a mistake or want to do this, please do not hesitate to request an edit.

I'm actually a Gradle sect, but I tried various things with Gradle, but there were twists and turns and I stopped it. Maybe it's okay if you do it with Uchiyoi-chan.

I put this code on Github.

Things necessary

Application creation

Create with Maven Archetype. I think this is probably the best way to make it.

mvn archetype:generate -Dappengine-version=1.9.54 \
-Djava8=true \
-DCloudSDK_Tooling=true \
-DuseObjectify=true \
-Dapplication-id=your-app-id \
-Dfilter=com.google.appengine.archetypes:

It seems that Objectify is recommended when using Datastore, so if you specify ʻuseObjectify` with True, it will be added to the dependency from the beginning.

If you do a little loading and so on, the output will be as follows.

[INFO] Generating project in Interactive mode
[INFO] No archetype defined. Using maven-archetype-quickstart (org.apache.maven.archetypes:maven-archetype-quickstart:1.0)
Choose archetype:
1: remote -> com.google.appengine.archetypes:appengine-flexible-archetype (A basic Java application with Google App Engine flexible.)
2: remote -> com.google.appengine.archetypes:appengine-skeleton-archetype (A skeleton application with Google App Engine)
3: remote -> com.google.appengine.archetypes:appengine-standard-archetype (A basic Java application with Google App Engine Standard)
4: remote -> com.google.appengine.archetypes:endpoints-skeleton-archetype (A skeleton project using Cloud Endpoints Frameworks with Google App Engine Standard)
5: remote -> com.google.appengine.archetypes:guestbook-archetype (A guestbook application with Google App Engine)
6: remote -> com.google.appengine.archetypes:hello-endpoints-archetype (A simple starter application using Cloud Endpoints Frameworks with Google App Engine Standard)
7: remote -> com.google.appengine.archetypes:skeleton-archetype (Archetype with a README about Google App Engine archetypes)

Even if you look at the official explanation, you can't decide which one to choose, but I think it's good with 3. Is it around 4 for those who want to use Cloud Endpoints? I haven't seen it properly, but the difference is whether Objectify can be specified at the time of creation and if the version of Mockito is Skelton (2), it is 2.0 β. There is no difference in the generated code. Or rather, it runs in Spring Boot, so I'll throw away the generated Java code later.

The rest will be asked for Group ID, Artifact ID, Package, etc., so answer it.

This completes the source code for App Engine SE that runs on Java 8. It just contains Hello World.

Development environment

IDEA settings

The App Engine plugin may be included by default. This is Deprecated, so let's disable it.

--Install the Google Cloud Tools plugin --Disable Google App Engine plugin

Please refer to here for details.

スクリーンショット 2017-08-29 16.23.17.png

It is invalid because it is built in and I think it cannot be uninstalled. I think that it will disappear with the version upgrade soon.

For other Cloud SDK and other settings, I think you should refer to the official one. スクリーンショット 2017-08-29 17.12.52.png スクリーンショット 2017-08-29 17.12.24.png

スクリーンショット 2017-08-29 17.18.04.png

Creating a project

Create an empty project as you like. Import Module there.

Please specify Java 8 as the SDK of the project.

スクリーンショット 2017-08-29 17.13.36.png

Add module

Import the created application into the IntteliJ project.

スクリーンショット 2017-08-29 17.13.46.png

Please specify pom.xml and import.

スクリーンショット 2017-08-29 17.15.12.png

If you import and close the Project Structure window, GAE will be detected and set at the bottom right, so please configure.

スクリーンショット 2017-08-29 17.15.25.png

It then reads the air, reads the settings, and allows you to run local server and deployment settings on IntelliJ.

For deployment, you have to configure the project with Edit Configure after this.

Deployment settings

スクリーンショット 2017-08-29 17.16.11.png

Select Deploy. If you choose something like a present mark, it's OK.

Then, the deployment settings and project settings will appear below.

スクリーンショット_2017-08-29_17_16_35.png

You have to log in for the first time, so click the button to open the browser and log in. If it is authenticated, some projects you own will appear like an image, so select the target GCP project.

Deployment options

スクリーンショット 2017-08-29 17.17.01.png

It seems better to set the Version to Auto Generate. If you want to have the deployed version of traffic immediately, you can turn on Promote the deployed version to receive all traffic. If there are updates such as Cron and Index, it would be better to turn on Update Hogehoge.

Spring Boot

Add dependency

Let's play with pom.xml. App Engine seems to be Jetty, so you need to exclude the Spring Boot default Tomcat.

Added to <dependencies>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <version>${spring.boot.version}</version>
            <!-- Exclude Tomcat so that it doesn't conflict w/ Jetty server -->
            <exclusions>
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-tomcat</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <!-- Exclude any jul-to-slf4j -->
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>jul-to-slf4j</artifactId>
            <scope>provided</scope>
        </dependency>

Added <dependencyManagement>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <!-- Import dependency management from Spring Boot -->
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-dependencies</artifactId>
                <version>${spring.boot.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

Added to <plugins>

            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <version>${spring.boot.version}</version>
            </plugin>

Added to <properties>

        <spring.boot.version>1.5.6.RELEASE</spring.boot.version>

After that, please implement Spring Boot Application normally. It is okay to delete the HelloAppEngine and index.jsp generated by the archetype.

Turn off the banner output at startup

It is recommended to turn it off because it will be annoying to appear in Logging. When it is ON, it looks like this.

スクリーンショット 2017-08-29 17.25.28.png

Let's add the setting to ʻapplication.yml`.

spring:
    main:
        banner-mode: "off"

Summary

Kanso

It is an atmosphere that seems to be able to develop with Spring Boot normally. To be honest, I spent about a day wondering what the Maven task was wrong when I first read the documentation and the source code of the repository, but I think that this can be done if developing locally. .. If you start it with a command, you can use mvn app engine: run.

You may also try implementing the application properly.

What is the startup time?

It takes about 10 seconds to spin up and start working with this source code, which has almost no dependencies, on the first access. I can't say anything about this personally, so please make your own judgment. (I judged the startup time from the start of the Logging request to the end of the application startup log. Is this the case?) Please tell me how to measure it properly.

I don't think it's suitable for monolithic applications, which tend to be terribly slow to start for the first time if the dependency is set to Morimori.

bonus

I'm deploying maven's app engine plugin, but I'm using the gcloud app command.

Repository

The source code for this time is here

Recommended Posts

I tried Java8 + Spring Boot with GAE SE (and about its development environment)
I tried Google Sign-In with Spring Boot + Spring Security REST API
Java --Deploy Spring Boot project to GAE
I tried to build a Mac Python development environment with pythonz + direnv
I tried playing with PartiQL and MongoDB connected
I tried Jacobian and partial differential with python
I tried function synthesis and curry with python
I built an AWS Chalice development environment with docker and tried deploying a serverless application at super high speed
Virtualize (isolate) IBM i python development environment with chroot
I tried to read and save automatically with VOICEROID2 2
I tried to implement and learn DCGAN with PyTorch
I tried to automatically read and save with VOICEROID2
Manage Python runtime packages and development environment packages with Poetry
Install Ubuntu 20.04 with GUI and prepare the development environment
I tried to implement Grad-CAM with keras and tensorflow
[Python] Chapter 01-02 About Python (Execution and installation of development environment)
I tried web application development and thought about how to prevent beginners from getting sick.
About Python development environment
I tried to predict and submit Titanic survivors with Kaggle
Hello World with Google App Engine (Java 8) + Spring Boot + Gradle
I tried connecting Raspberry Pi and conect + with Web API
I tried follow management with Twitter API and Python (easy)
[Python] I tried to visualize tweets about Corona with WordCloud
I tried programming the chi-square test in Python and Java.
I tried to enumerate the differences between java and python
I tried to make GUI tic-tac-toe with Python and Tkinter
Hello World with Google App Engine (Java 11) + Spring Boot + Gradle
Is the Serverless environment more than 600 times slower? ~ I tried benchmarking with Go, Node.js and Python! ~