Skip to content

Commit 6eeefe0

Browse files
author
Jeff.Black
committed
Deploy Spring Boot app to CF
1 parent f5ae001 commit 6eeefe0

4 files changed

Lines changed: 56 additions & 3 deletions

File tree

build.gradle

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,15 @@ dependencies {
1515
// compile("org.springframework:spring-webmvc")
1616
// compile("org.springframework.boot:spring-boot-starter")
1717
// compile("org.springframework.boot:spring-boot-starter-tomcat")
18+
19+
testCompile("org.springframework.boot:spring-boot-starter-test")
20+
1821
}
22+
23+
bootRun.environment([
24+
"WELCOME_MESSAGE": "from gradle config",
25+
])
26+
27+
test.environment([
28+
"WELCOME_MESSAGE": "Hello from test",
29+
])

manifest.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
applications:
3+
- name: pal-tracker
4+
path: build/libs/pal-tracker.jar
5+
random-route: true
6+
env:
7+
WELCOME_MESSAGE: Hello from Cloud Foundry
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package io.pivotal.pal.tracker;
2+
3+
import org.springframework.beans.factory.annotation.Value;
4+
import org.springframework.web.bind.annotation.GetMapping;
5+
import org.springframework.web.bind.annotation.RestController;
6+
7+
import java.util.HashMap;
8+
import java.util.Map;
9+
10+
@RestController
11+
public class EnvController {
12+
13+
public Map<String, String> envMap = new HashMap<String,String>();
14+
15+
public EnvController(@Value("${PORT:NOT_SET}") String port, @Value("${MEMORY_LIMIT:NOT_SET}") String memoryLimit,
16+
@Value("${CF_INSTANCE_INDEX:NOT_SET}") String cfInstanceIndex, @Value("${CF_INSTANCE_ADDR:NOT_SET}") String cfInstanceAddr) {
17+
envMap.put("PORT", port);
18+
envMap.put("MEMORY_LIMIT", memoryLimit);
19+
envMap.put("CF_INSTANCE_INDEX", cfInstanceIndex);
20+
envMap.put("CF_INSTANCE_ADDR", cfInstanceAddr);
21+
}
22+
23+
@GetMapping("/env")
24+
public Map<String, String> getEnv() {
25+
return envMap;
26+
}
27+
28+
}
Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
11
package io.pivotal.pal.tracker;
22

3+
import org.springframework.beans.factory.annotation.Value;
34
import org.springframework.web.bind.annotation.GetMapping;
45
import org.springframework.web.bind.annotation.RestController;
56

67
@RestController
78
public class WelcomeController {
89

10+
private static String greeting = "hello";
11+
12+
public WelcomeController(@Value("${WELCOME_MESSAGE}") String greetingToUse) {
13+
greeting = greetingToUse;
14+
}
15+
916
@GetMapping("/")
10-
public String sayHello() {
11-
return "hello";
12-
}
17+
public String sayHello() {
18+
return greeting;
19+
}
1320
}

0 commit comments

Comments
 (0)