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.
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.
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.
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.
Create an empty project as you like. Import Module there.
Please specify Java 8 as the SDK of the project.
Import the created application into the IntteliJ project.
Please specify pom.xml and import.
If you import and close the Project Structure window, GAE will be detected and set at the bottom right, so please configure.
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.
Select Deploy. If you choose something like a present mark, it's OK.
Then, the deployment settings and project settings will appear below.
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
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.
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.
It is recommended to turn it off because it will be annoying to appear in Logging. When it is ON, it looks like this.
Let's add the setting to ʻapplication.yml`.
spring:
main:
banner-mode: "off"
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.
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.
I'm deploying maven's app engine plugin, but I'm using the gcloud app
command.
The source code for this time is here
Recommended Posts