Skip to content

Commit 6d880cf

Browse files
committed
Merge pull request #2707 from nebhale/vcap-service-numbers
* vcap-service-numbers: Support VcapApplicationListener Number Credentials
2 parents 1fba81e + 147755f commit 6d880cf

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

spring-boot/src/main/java/org/springframework/boot/cloudfoundry/VcapApplicationListener.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2010-2014 the original author or authors.
2+
* Copyright 2010-2015 the original author or authors.
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.
@@ -213,6 +213,9 @@ private void flatten(Properties properties, Map<String, Object> input, String pa
213213
if (value instanceof String) {
214214
properties.put(key, value);
215215
}
216+
else if (value instanceof Number) {
217+
properties.put(key, value.toString());
218+
}
216219
else if (value instanceof Map) {
217220
// Need a compound key
218221
@SuppressWarnings("unchecked")

spring-boot/src/test/java/org/springframework/boot/cloudfoundry/VcapApplicationListenerTests.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2014 the original author or authors.
2+
* Copyright 2012-2015 the original author or authors.
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.
@@ -75,6 +75,10 @@ public void testServiceProperties() {
7575
this.initializer.onApplicationEvent(this.event);
7676
assertEquals("mysql",
7777
this.context.getEnvironment().getProperty("vcap.services.mysql.name"));
78+
assertEquals(
79+
"3306",
80+
this.context.getEnvironment().getProperty(
81+
"vcap.services.mysql.credentials.port"));
7882
}
7983

8084
@Test
@@ -86,5 +90,9 @@ public void testServicePropertiesWithoutNA() {
8690
this.initializer.onApplicationEvent(this.event);
8791
assertEquals("mysql",
8892
this.context.getEnvironment().getProperty("vcap.services.mysql.name"));
93+
assertEquals(
94+
"3306",
95+
this.context.getEnvironment().getProperty(
96+
"vcap.services.mysql.credentials.port"));
8997
}
9098
}

0 commit comments

Comments
 (0)