Skip to content

Commit 36f5996

Browse files
authored
update Springboot to use application.properties for port (GoogleCloudPlatform#3343)
1 parent fc3aadc commit 36f5996

File tree

14 files changed

+76
-41
lines changed

14 files changed

+76
-41
lines changed

run/events-pubsub/src/main/java/com/example/cloudrun/Application.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@
2323
@SpringBootApplication
2424
public class Application {
2525
public static void main(String[] args) {
26-
String port = System.getenv().getOrDefault("PORT", "8080");
27-
System.setProperty("server.port", port);
2826
SpringApplication.run(Application.class, args);
2927
}
3028
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Copyright 2020 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.
14+
server.port=${PORT:8080}

run/events-storage/src/main/java/com/example/cloudrun/Application.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@
2323
@SpringBootApplication
2424
public class Application {
2525
public static void main(String[] args) {
26-
String port = System.getenv().getOrDefault("PORT", "8080");
27-
System.setProperty("server.port", port);
2826
SpringApplication.run(Application.class, args);
2927
}
3028
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Copyright 2020 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.
14+
server.port=${PORT:8080}

run/helloworld/src/main/java/com/example/helloworld/HelloworldApplication.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@ String hello() {
3737
}
3838

3939
public static void main(String[] args) {
40-
String port = System.getenv().getOrDefault("PORT", "8080");
41-
System.setProperty("server.port", port);
4240
SpringApplication.run(HelloworldApplication.class, args);
4341
}
4442
}

run/helloworld/src/main/resources/application.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14+
server.port=${PORT:8080}

run/image-processing/src/main/java/com/example/cloudrun/PubSubApplication.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@
2222
@SpringBootApplication
2323
public class PubSubApplication {
2424
public static void main(String[] args) {
25-
String port = System.getenv().getOrDefault("PORT", "8080");
26-
System.setProperty("server.port", port);
2725
SpringApplication.run(PubSubApplication.class, args);
2826
}
2927
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Copyright 2020 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.
14+
server.port=${PORT:8080}

run/markdown-preview/editor/src/main/java/com/example/cloudrun/EditorApplication.java

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,9 @@ public class EditorApplication {
2828
private static final Logger logger = LoggerFactory.getLogger(EditorApplication.class);
2929

3030
public static void main(String[] args) {
31-
String port = System.getenv("PORT");
32-
if (port == null) {
33-
port = "8080";
34-
logger.warn("Defaulting to port " + port);
35-
}
36-
SpringApplication app = new SpringApplication(EditorApplication.class);
37-
app.setDefaultProperties(Collections.singletonMap("server.port", port));
38-
3931
// Start the Spring Boot application.
40-
app.run(args);
32+
SpringApplication.run(EditorApplication.class, args);
33+
String port = System.getenv().getOrDefault("PORT", "8080");
4134
logger.info("Listening on port " + port);
4235
}
4336
}

run/markdown-preview/editor/src/main/resources/application.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14+
server.port=${PORT:8080}

run/markdown-preview/renderer/src/main/java/com/example/cloudrun/RendererApplication.java

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,9 @@ public class RendererApplication {
2828
private static final Logger logger = LoggerFactory.getLogger(RendererApplication.class);
2929

3030
public static void main(String[] args) {
31-
String port = System.getenv("PORT");
32-
if (port == null) {
33-
port = "8080";
34-
logger.warn("Defaulting to port " + port);
35-
}
36-
SpringApplication app = new SpringApplication(RendererApplication.class);
37-
app.setDefaultProperties(Collections.singletonMap("server.port", port));
38-
3931
// Start the Spring Boot application.
40-
app.run(args);
32+
SpringApplication.run(RendererApplication.class, args);
33+
String port = System.getenv().getOrDefault("PORT", "8080");
4134
logger.info("Listening on port " + port);
4235
}
4336
}
Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
# Copyright 2020 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.
1+
# Copyright 2020 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.
14+
server.port=${PORT:8080}

run/pubsub/src/main/java/com/example/cloudrun/PubSubApplication.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@
2323
@SpringBootApplication
2424
public class PubSubApplication {
2525
public static void main(String[] args) {
26-
String port = System.getenv().getOrDefault("PORT", "8080");
27-
System.setProperty("server.port", port);
2826
SpringApplication.run(PubSubApplication.class, args);
2927
}
3028
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Copyright 2020 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.
14+
server.port=${PORT:8080}

0 commit comments

Comments
 (0)