mirror of https://github.com/knative/docs.git
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:
parent
7987f30e82
commit
30280191ef
|
@ -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"]
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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}
|
Loading…
Reference in New Issue