Update Java Spring boot sample to programmatically get PORT (#2173)

* Update Java Springboot sample to programmatically get PORT

* update readme

* Clean up
This commit is contained in:
Averi Kitsch 2020-02-11 12:10:22 -08:00 committed by GitHub
parent 7987f30e82
commit 30280191ef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 41 additions and 26 deletions

View File

@ -20,4 +20,4 @@ FROM adoptopenjdk/openjdk8:jdk8u202-b08-alpine-slim
COPY --from=builder /app/target/helloworld-*.jar /helloworld.jar
# Run the web service on container startup.
CMD ["java","-Djava.security.egd=file:/dev/./urandom","-Dserver.port=${PORT}","-jar","/helloworld.jar"]
CMD ["java", "-Djava.security.egd=file:/dev/./urandom", "-jar", "/helloworld.jar"]

View File

@ -64,20 +64,20 @@ cd knative-docs/docs/serving/samples/hello-world/helloworld-java-spring
@SpringBootApplication
public class HelloworldApplication {
@Value("${TARGET:World}")
String target;
@Value("${TARGET:World}")
String target;
@RestController
class HelloworldController {
@GetMapping("/")
String hello() {
return "Hello " + target + "!";
}
}
@RestController
class HelloworldController {
@GetMapping("/")
String hello() {
return "Hello " + target + "!";
}
}
public static void main(String[] args) {
SpringApplication.run(HelloworldApplication.class, args);
}
public static void main(String[] args) {
SpringApplication.run(HelloworldApplication.class, args);
}
}
```
@ -119,7 +119,7 @@ cd knative-docs/docs/serving/samples/hello-world/helloworld-java-spring
COPY --from=builder /app/target/helloworld-*.jar /helloworld.jar
# Run the web service on container startup.
CMD ["java","-Djava.security.egd=file:/dev/./urandom","-Dserver.port=${PORT}","-jar","/helloworld.jar"]
CMD ["java", "-Djava.security.egd=file:/dev/./urandom", "-jar", "/helloworld.jar"]
```
1. Create a new file, `service.yaml` and copy the following service definition

View File

@ -9,18 +9,18 @@ import org.springframework.web.bind.annotation.RestController;
@SpringBootApplication
public class HelloworldApplication {
@Value("${TARGET:World}")
String target;
@Value("${TARGET:World}")
String target;
@RestController
class HelloworldController {
@GetMapping("/")
String hello() {
return "Hello " + target + "!";
}
}
@RestController
class HelloworldController {
@GetMapping("/")
String hello() {
return "Hello " + target + "!";
}
}
public static void main(String[] args) {
SpringApplication.run(HelloworldApplication.class, args);
}
public static void main(String[] args) {
SpringApplication.run(HelloworldApplication.class, args);
}
}

View File

@ -0,0 +1,15 @@
# Copyright 2020 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
server.port = ${PORT}