Skip to content

Commit 4fff89e

Browse files
averikitschlesv
andauthored
Update springboot app for Flex (#2034)
* Update springboot app * lint * lint * Add note for plugin version * Undo license changes and add note about plugin * move to correct folder Co-authored-by: Les Vogel <[email protected]>
1 parent ddbe584 commit 4fff89e

File tree

10 files changed

+213
-131
lines changed

10 files changed

+213
-131
lines changed

appengine-java8/helloworld-springboot/src/main/resources/application.properties

Lines changed: 0 additions & 14 deletions
This file was deleted.

appengine-java8/helloworld-springboot/src/test/java/com/example/java/gettingstarted/it/HelloWorldApplicationIT.java

Lines changed: 0 additions & 47 deletions
This file was deleted.

appengine-java8/helloworld-springboot/README.md renamed to flexible/helloworld-springboot/README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,11 @@ These settings should be revisited for production use.
8484

8585
## Deploy to App Engine flexible environment
8686

87-
1. `mvn appengine:deploy`
87+
1. `mvn clean package appengine:deploy`
88+
89+
* Note: The `projectId` property for the `appengine-maven-plugin` is set to
90+
"GCLOUD_CONFIG" which will deploy using the gcloud settings for `projectId`.
91+
8892
1. Visit `http://YOUR_PROJECT.appspot.com`.
8993

9094
Note that deployment to the App Engine flexible environment requires the new
@@ -93,4 +97,3 @@ Note that deployment to the App Engine flexible environment requires the new
9397
[new-maven-plugin]: https://cloud.google.com/appengine/docs/flexible/java/using-maven
9498

9599
Java is a registered trademark of Oracle Corporation and/or its affiliates.
96-
Lines changed: 54 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
12
<!--
2-
~ Copyright (c) 2013 Google Inc.
3+
~ Copyright (c) 2013 Google LLC
34
~
45
~ Licensed under the Apache License, Version 2.0 (the "License"); you
56
~ may not use this file except in compliance with the License. You may
@@ -13,16 +14,12 @@
1314
~ implied. See the License for the specific language governing
1415
~ permissions and limitations under the License.
1516
-->
16-
<project>
17-
<modelVersion>4.0.0</modelVersion>
18-
19-
<groupId>com.example.flex.gettingstarted</groupId>
20-
<artifactId>helloworld-springboot</artifactId>
21-
<version>0.0.1-SNAPSHOT</version>
22-
<packaging>jar</packaging>
23-
17+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
18+
<modelVersion>4.0.0</modelVersion>
19+
<groupId>com.example.java</groupId>
20+
<artifactId>helloworld-springboot</artifactId>
21+
<version>0.0.1-SNAPSHOT</version>
2422
<name>helloworld-springboot</name>
25-
<description>Demo project for Spring Boot</description>
2623

2724
<!--
2825
The parent pom defines common style checks and testing strategies for our samples.
@@ -33,51 +30,55 @@
3330
<artifactId>shared-configuration</artifactId>
3431
<version>1.0.11</version>
3532
</parent>
36-
37-
<properties>
38-
<java.version>1.8</java.version>
39-
<maven.compiler.source>${java.version}</maven.compiler.source> <!-- REQUIRED -->
40-
<maven.compiler.target>${java.version}</maven.compiler.target> <!-- REQUIRED -->
41-
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
42-
<appengine.maven.plugin>1.3.2</appengine.maven.plugin>
33+
34+
<properties>
35+
<maven.compiler.source>1.8</maven.compiler.source>
36+
<maven.compiler.target>1.8</maven.compiler.target>
4337
</properties>
44-
45-
<dependencies>
46-
<dependency>
47-
<groupId>org.springframework.boot</groupId>
38+
39+
<dependencies>
40+
<dependency>
41+
<groupId>org.springframework.boot</groupId>
4842
<artifactId>spring-boot-starter-web</artifactId>
49-
<version>2.2.2.RELEASE</version>
50-
</dependency>
51-
52-
<dependency>
53-
<groupId>org.springframework.boot</groupId>
43+
<version>2.2.2.RELEASE</version>
44+
</dependency>
45+
<dependency>
46+
<groupId>org.springframework.boot</groupId>
47+
<artifactId>spring-boot-starter-actuator</artifactId>
48+
<version>2.2.2.RELEASE</version>
49+
</dependency>
50+
<dependency>
51+
<groupId>org.springframework.boot</groupId>
5452
<artifactId>spring-boot-starter-test</artifactId>
55-
<version>2.2.2.RELEASE</version>
56-
<scope>test</scope>
57-
</dependency>
53+
<version>2.2.2.RELEASE</version>
54+
<scope>test</scope>
55+
<exclusions>
56+
<exclusion>
57+
<groupId>org.junit.vintage</groupId>
58+
<artifactId>junit-vintage-engine</artifactId>
59+
</exclusion>
60+
</exclusions>
61+
</dependency>
5862
</dependencies>
59-
60-
<build>
61-
<plugins>
62-
<plugin>
63-
<groupId>org.springframework.boot</groupId>
63+
64+
<build>
65+
<plugins>
66+
<plugin>
67+
<groupId>org.springframework.boot</groupId>
6468
<artifactId>spring-boot-maven-plugin</artifactId>
65-
<version>1.5.7.RELEASE</version>
66-
<executions>
67-
<execution>
68-
<goals>
69-
<goal>repackage</goal>
70-
</goals>
71-
</execution>
72-
</executions>
73-
</plugin>
74-
<!-- START plugin -->
75-
<plugin>
76-
<groupId>com.google.cloud.tools</groupId>
77-
<artifactId>appengine-maven-plugin</artifactId>
78-
<version>${appengine.maven.plugin}</version>
79-
</plugin>
80-
<!-- END plugin -->
81-
</plugins>
82-
</build>
83-
</project>
69+
<version>2.2.2.RELEASE</version>
70+
</plugin>
71+
<plugin>
72+
<groupId>com.google.cloud.tools</groupId>
73+
<artifactId>appengine-maven-plugin</artifactId>
74+
<version>2.2.0</version>
75+
<configuration>
76+
<!-- setting a property to "GCLOUD_CONFIG" will deploy using the gcloud settings for the property -->
77+
<projectId>GCLOUD_CONFIG</projectId>
78+
<!-- set the GAE version or use "GCLOUD_CONFIG" for an autogenerated GAE version -->
79+
<version>GCLOUD_CONFIG</version>
80+
</configuration>
81+
</plugin>
82+
</plugins>
83+
</build>
84+
</project>

appengine-java8/helloworld-springboot/src/main/appengine/app.yaml renamed to flexible/helloworld-springboot/src/main/appengine/app.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# [START_EXCLUDE]
2-
# Copyright 2015 Google Inc.
2+
# Copyright 2015 Google LLC
33
#
44
# Licensed under the Apache License, Version 2.0 (the "License");
55
# you may not use this file except in compliance with the License.
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2015 Google Inc.
2+
* Copyright 2020 Google LLC
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -14,34 +14,29 @@
1414
* limitations under the License.
1515
*/
1616

17-
package com.example.java.gettingstarted;
17+
package com.example.java;
1818

19-
import org.springframework.boot.SpringApplication;
20-
import org.springframework.boot.autoconfigure.SpringBootApplication;
2119
import org.springframework.web.bind.annotation.RequestMapping;
2220
import org.springframework.web.bind.annotation.RestController;
2321

24-
@SpringBootApplication
2522
@RestController
26-
public class HelloworldApplication {
23+
public class HelloController {
2724
@RequestMapping("/")
28-
public String home() {
25+
String index() {
2926
return "Hello World!";
3027
}
3128

3229
/**
3330
* (Optional) App Engine health check endpoint mapping.
34-
* @see <a href="https://cloud.google.com/appengine/docs/flexible/java/how-instances-are-managed#health_checking"></a>
35-
* If your app does not handle health checks, a HTTP 404 response is interpreted
36-
* as a successful reply.
31+
*
32+
* @see <a
33+
* href="https://cloud.google.com/appengine/docs/flexible/java/how-instances-are-managed#health_checking"></a>
34+
* If your app does not handle health checks, a HTTP 404 response is interpreted as a
35+
* successful reply.
3736
*/
3837
@RequestMapping("/_ah/health")
3938
public String healthy() {
4039
// Message body required though ignored
4140
return "Still surviving.";
4241
}
43-
44-
public static void main(String[] args) {
45-
SpringApplication.run(HelloworldApplication.class, args);
46-
}
4742
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* Copyright 2015 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.example.java;
18+
19+
import org.springframework.boot.SpringApplication;
20+
import org.springframework.boot.autoconfigure.SpringBootApplication;
21+
22+
@SpringBootApplication
23+
public class HelloWorldApplication {
24+
25+
public static void main(String[] args) {
26+
SpringApplication.run(HelloWorldApplication.class, args);
27+
}
28+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Copyright 2015 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* Copyright 2015 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.example.java;
18+
19+
import static org.assertj.core.api.Assertions.assertThat;
20+
21+
import java.net.URL;
22+
import org.junit.jupiter.api.Test;
23+
import org.springframework.beans.factory.annotation.Autowired;
24+
import org.springframework.boot.test.context.SpringBootTest;
25+
import org.springframework.boot.test.web.client.TestRestTemplate;
26+
import org.springframework.boot.web.server.LocalServerPort;
27+
import org.springframework.http.ResponseEntity;
28+
29+
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
30+
public class HelloControllerIT {
31+
32+
@LocalServerPort private int port;
33+
34+
private URL base;
35+
36+
@Autowired private TestRestTemplate template;
37+
38+
@Test
39+
@SuppressWarnings("CheckReturnValue")
40+
public void getHello() throws Exception {
41+
URL base = new URL("http://localhost:" + port + "/");
42+
ResponseEntity<String> response = template.getForEntity(base.toString(), String.class);
43+
assertThat(response.getBody().equals("Hello World!"));
44+
}
45+
46+
@Test
47+
@SuppressWarnings("CheckReturnValue")
48+
public void getHealth() throws Exception {
49+
URL base = new URL("http://localhost:" + port + "/_ah/health");
50+
ResponseEntity<String> response = template.getForEntity(base.toString(), String.class);
51+
assertThat(response.getBody().equals("Hello World!"));
52+
}
53+
}

0 commit comments

Comments
 (0)