Skip to content

Commit a28f457

Browse files
Spring Boot 3 support, no support to 2.x (#214)
* Upgrade dependencies and tools * CI should run on Java 17, it's an LTS version * use more recent gradle to support Java 17 * Upgrade Spring boot version to latest bug fix * Close #204: Allow java-cfenv to work with Spring Boot 3 * Redis and Cassandra * Close #204: Add integration tests * Close #204 SpringBoot3-only support on main branch * Fix after review by @abelsromero * Close #204: re indent, remove unused method * Close #204: remove Jacoco for now, incompatibility with JMockit and Java 17, see: jmockit/jmockit1#615 and https://github.com/jmockit/jmockit1
1 parent 613acaf commit a28f457

File tree

19 files changed

+284
-76
lines changed

19 files changed

+284
-76
lines changed

.github/workflows/build.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ jobs:
1111
runs-on: ubuntu-latest
1212
strategy:
1313
matrix:
14-
java: [ '8', '11' ]
14+
java: [ '17' ]
1515
name: Java ${{ matrix.Java }} build
1616
steps:
1717
- uses: actions/checkout@v2
1818
- name: Set up JDK
19-
uses: actions/setup-java@v2
19+
uses: actions/setup-java@v3
2020
with:
2121
java-version: ${{ matrix.java }}
2222
distribution: adopt

README.adoc

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
== Java CFEnv image:https://build.spring.io/plugins/servlet/wittified/build-status/CFENV-BMASTER[Build Status, link=https://build.spring.io/browse/CFENV-BMASTER]
1+
= Java CFEnv image:https://build.spring.io/plugins/servlet/wittified/build-status/CFENV-BMASTER[Build Status, link=https://build.spring.io/browse/CFENV-BMASTER]
22

33
Java CFEnv is a library for easily accessing the environment variables set when deploying an application to Cloud Foundry.
44
It is modeled after the design of the node library https://github.com/cloudfoundry-community/node-cfenv/[node-cfenv] and other `-cfenv` libraries in the Cloud Foundry ecosystem.
@@ -9,6 +9,20 @@ CFEnv's Boot support sets https://docs.spring.io/spring-boot/docs/current/refere
99

1010
The https://spring.io/blog/2019/02/15/introducing-java-cfenv-a-new-library-for-accessing-cloud-foundry-services[1.0 M1 blog] provides some additional background information.
1111

12+
== Compatibility
13+
=== https://github.com/pivotal-cf/java-cfenv/tree/main[3.x]
14+
15+
* https://projects.spring.io/spring-framework/[Spring Framework] 6.x
16+
17+
* https://projects.spring.io/spring-boot/[Spring Boot] 3.x
18+
19+
20+
=== https://github.com/pivotal-cf/java-cfenv/tree/2.5.x[2.x]
21+
22+
* https://projects.spring.io/spring-framework/[Spring Framework] 5.3+
23+
24+
* https://projects.spring.io/spring-boot/[Spring Boot] 2.5+
25+
1226
== Dependency Info
1327

1428
You can access the stable release from maven central using the coordinates
@@ -18,7 +32,7 @@ You can access the stable release from maven central using the coordinates
1832
<dependency>
1933
<groupId>io.pivotal.cfenv</groupId>
2034
<artifactId>java-cfenv-boot</artifactId>
21-
<version>2.4.0</version>
35+
<version>3.0.0</version>
2236
</dependency>
2337
----
2438

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
buildscript {
22
ext {
33
jmockitVersion = "1.49"
4-
springBootVersion = "2.6.6"
4+
springBootVersion = "3.1.0"
55
}
66
}
77

buildSrc/src/main/groovy/io.pivotal.cfenv.java-conventions.gradle

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,11 @@ plugins {
44
id 'java-library'
55
id 'maven-publish'
66
id 'checkstyle'
7-
id 'jacoco'
87
}
98

109
ext {
11-
springFrameworkVersion = "5.3.8"
12-
javaApi = "https://docs.oracle.com/javase/8/docs/api/"
13-
if (JavaVersion.current() >= JavaVersion.VERSION_11) {
14-
javaApi = "https://docs.oracle.com/en/java/javase/11/docs/api"
15-
}
10+
springFrameworkVersion = "6.0.9"
11+
javaApi = "https://docs.oracle.com/javase/17/docs/api/"
1612
javadocLinks = [
1713
javaApi,
1814
"https://docs.spring.io/spring-framework/docs/${springFrameworkVersion}/javadoc-api/"
@@ -23,7 +19,7 @@ java {
2319
withJavadocJar()
2420
withSourcesJar()
2521
toolchain {
26-
languageVersion = JavaLanguageVersion.of(8)
22+
languageVersion = JavaLanguageVersion.of(17)
2723
}
2824
}
2925

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
org.gradle.parallel=true
22

33
group=io.pivotal.cfenv
4-
version=2.4.3-SNAPSHOT
4+
version=3.0.0-SNAPSHOT
55
onlyShowStandardStreamsOnTestFailure=false
66

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-7.1.1-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.1-bin.zip
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists

java-cfenv-boot/README.adoc

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
=== Redis
2+
Type: `redis`
3+
Disable Property: `cfenv.service.redis.enabled`
4+
5+
==== Spring Boot 3 properties
6+
7+
| Property | Value |
8+
|-------------------------------------------|---------------------------|
9+
| `spring.data.redis.host` | `{host}` |
10+
| `spring.data.redis.password` | `{password}` |
11+
| `spring.data.redis.port` | `{port}` |
12+
| `spring.data.redis.ssl` | `{ssl}` |
13+
14+
Not supported, compared to `spring-cloud-bindings`:
15+
16+
| Property | Value |
17+
|-------------------------------------------|---------------------------|
18+
| `spring.data.redis.client-name` | `{client-name}` |
19+
| `spring.data.redis.cluster.max-redirects` | `{cluster.max-redirects}` |
20+
| `spring.data.redis.cluster.nodes` | `{cluster.nodes}` |
21+
| `spring.data.redis.database` | `{database}` |
22+
| `spring.data.redis.sentinel.master` | `{sentinel.master}` |
23+
| `spring.data.redis.sentinel.nodes` | `{sentinel.nodes}` |
24+
| `spring.data.redis.url` | `{url}` |

java-cfenv-boot/src/main/java/io/pivotal/cfenv/spring/boot/CassandraCfEnvProcessor.java

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
*/
2929
public class CassandraCfEnvProcessor implements CfEnvProcessor {
3030

31+
private static final String PREFIX = "spring.cassandra";
32+
3133
@Override
3234
public boolean accept(CfService service) {
3335
boolean serviceIsBound = service.existsByTagIgnoreCase("cassandra") &&
@@ -40,24 +42,23 @@ public boolean accept(CfService service) {
4042

4143
@Override
4244
public void process(CfCredentials cfCredentials, Map<String, Object> properties) {
43-
properties.put("spring.data.cassandra.username", cfCredentials.getUsername());
44-
properties.put("spring.data.cassandra.password", cfCredentials.getPassword());
45-
properties.put("spring.data.cassandra.port", cfCredentials.getMap().get("cqlsh_port"));
45+
properties.put(PREFIX + ".username", cfCredentials.getUsername());
46+
properties.put(PREFIX + ".password", cfCredentials.getPassword());
47+
properties.put(PREFIX + ".port", cfCredentials.getMap().get("cqlsh_port"));
4648
ArrayList<String> contactPoints = (ArrayList<String>) cfCredentials.getMap().get("node_ips");
47-
properties.put("spring.data.cassandra.contact-points",
49+
properties.put(PREFIX + ".contact-points",
4850
StringUtils.collectionToCommaDelimitedString(contactPoints));
51+
}
4952

53+
@Override
54+
public CfEnvProcessorProperties getProperties() {
55+
return CfEnvProcessorProperties.builder().propertyPrefixes(PREFIX)
56+
.serviceName("Cassandra").build();
5057
}
5158

52-
private boolean cassandraCredentialsPresent(Map<String, Object> credentials) {
59+
static boolean cassandraCredentialsPresent(Map<String, Object> credentials) {
5360
return credentials != null &&
5461
credentials.containsKey("cqlsh_port") &&
5562
credentials.containsKey("node_ips");
5663
}
57-
58-
@Override
59-
public CfEnvProcessorProperties getProperties() {
60-
return CfEnvProcessorProperties.builder().propertyPrefixes("spring.data.cassandra")
61-
.serviceName("Cassandra").build();
62-
}
6364
}

java-cfenv-boot/src/main/java/io/pivotal/cfenv/spring/boot/CfDataSourceEnvironmentPostProcessor.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
import org.springframework.boot.SpringApplication;
2424
import org.springframework.boot.cloud.CloudPlatform;
25-
import org.springframework.boot.context.config.ConfigFileApplicationListener;
25+
import org.springframework.boot.context.config.ConfigDataEnvironmentPostProcessor;
2626
import org.springframework.boot.context.event.ApplicationPreparedEvent;
2727
import org.springframework.context.ApplicationEvent;
2828
import org.springframework.context.ApplicationListener;
@@ -47,7 +47,7 @@ public class CfDataSourceEnvironmentPostProcessor implements CfServiceEnablingEn
4747
private static int invocationCount;
4848

4949
// After ConfigFileApplicationListener so values from files can be used here
50-
private int order = ConfigFileApplicationListener.DEFAULT_ORDER + 1;
50+
private int order = ConfigDataEnvironmentPostProcessor.ORDER + 1;
5151

5252
@Override
5353
public int getOrder() {
@@ -64,7 +64,7 @@ public void postProcessEnvironment(ConfigurableEnvironment environment,
6464
increaseInvocationCount();
6565
if (CloudPlatform.CLOUD_FOUNDRY.isActive(environment)) {
6666
CfJdbcEnv cfJdbcEnv = new CfJdbcEnv();
67-
CfJdbcService cfJdbcService = null;
67+
CfJdbcService cfJdbcService;
6868
try {
6969
cfJdbcService = cfJdbcEnv.findJdbcService();
7070
cfJdbcService = this.isEnabled(cfJdbcService, environment) ? cfJdbcService : null;

java-cfenv-boot/src/main/java/io/pivotal/cfenv/spring/boot/CfEnvironmentPostProcessor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
import org.springframework.boot.SpringApplication;
2424
import org.springframework.boot.cloud.CloudPlatform;
25-
import org.springframework.boot.context.config.ConfigFileApplicationListener;
25+
import org.springframework.boot.context.config.ConfigDataEnvironmentPostProcessor;
2626
import org.springframework.boot.context.event.ApplicationPreparedEvent;
2727
import org.springframework.context.ApplicationEvent;
2828
import org.springframework.context.ApplicationListener;
@@ -57,7 +57,7 @@ public class CfEnvironmentPostProcessor implements
5757
private static int invocationCount;
5858

5959
// After ConfigFileApplicationListener so values from files can be used here
60-
private int order = ConfigFileApplicationListener.DEFAULT_ORDER + 1;
60+
private int order = ConfigDataEnvironmentPostProcessor.ORDER + 1;
6161

6262
public CfEnvironmentPostProcessor() {
6363
}

0 commit comments

Comments
 (0)