Skip to content

Commit 2f6acf8

Browse files
committed
feat(cf-env): add Spring Boot 4.x support and improve docs
- Add detection tests for SB 4.0 and 4.1 (BOOT-INF/lib, lib/, WEB-INF/lib, MANIFEST.MF) - Update detection criterion to cover both SB 3.x and 4.x - Add version mapping table: SB 3.x → cfenv 3.x, SB 4.x → cfenv 4.x - Clarify cloud profile is activated by the library at runtime, not the buildpack - Add JBP_CONFIG_JAVA_CF_ENV configuration section with enable/disable examples - Document when to disable (manual VCAP_SERVICES handling, unwanted cloud profile, conflicts)
1 parent dab9179 commit 2f6acf8

2 files changed

Lines changed: 56 additions & 11 deletions

File tree

docs/framework-java-cfenv.md

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,51 @@
11
# Java CfEnv Framework
2-
The Java CfEnv Framework provides the `java-cfenv` library for Spring Boot 3+ applications. This library sets various Spring Boot properties by parsing CloudFoundry variables such as `VCAP_SERVICES`, allowing Spring Boot's autoconfiguration to kick in.
2+
The Java CfEnv Framework provides the `java-cfenv` library for Spring Boot 3.x and 4.x applications. This library sets various Spring Boot properties by parsing CloudFoundry variables such as `VCAP_SERVICES`, allowing Spring Boot's autoconfiguration to kick in.
33

4-
This is the recommended replacement for Spring AutoReconfiguration library which is deprecated. See the `java-cfenv` <a href="https://github.com/pivotal-cf/java-cfenv">repostitory</a> for more detail.
4+
This is the recommended replacement for Spring AutoReconfiguration library which is deprecated. See the `java-cfenv` <a href="https://github.com/pivotal-cf/java-cfenv">repository</a> for more detail.
55

6-
It also sets the 'cloud' profile for Spring Boot applications, as the Spring AutoReconfiguration framework did.
6+
The included `java-cfenv` library activates the `cloud` Spring profile at runtime when `VCAP_SERVICES` is present, as the Spring AutoReconfiguration framework did. The buildpack itself does not set any Spring profile.
7+
8+
The buildpack selects the appropriate `java-cfenv` version based on the detected Spring Boot major version:
9+
10+
| Spring Boot | java-cfenv |
11+
|-------------|------------|
12+
| 3.x | 3.x (latest) |
13+
| 4.x | 4.x (latest) |
714

815
<table>
916
<tr>
1017
<td><strong>Detection Criterion</strong></td>
11-
<td>Existence of a `Spring-Boot-Version: 3.*` manifest entry</td>
12-
<td>No existing `java-cfenv` library found</td>
18+
<td>Existence of a <tt>spring-boot-3.*.jar</tt> or <tt>spring-boot-4.*.jar</tt> in <tt>BOOT-INF/lib</tt>, <tt>WEB-INF/lib</tt>, or <tt>lib/</tt>; or a <tt>Spring-Boot-Version: 3.*</tt> / <tt>Spring-Boot-Version: 4.*</tt> entry in <tt>META-INF/MANIFEST.MF</tt></td>
19+
<td>No existing <tt>java-cfenv</tt> library found in the application</td>
1320
</tr>
1421
<tr>
1522
<td><strong>Tags</strong></td>
1623
<td><tt>java-cf-env=&lt;version&gt;</tt></td>
1724
</tr>
1825
</table>
1926
Tags are printed to standard output by the buildpack detect script
27+
28+
## Configuration
29+
30+
The framework can be disabled via the `JBP_CONFIG_JAVA_CF_ENV` environment variable:
31+
32+
```bash
33+
cf set-env <app> JBP_CONFIG_JAVA_CF_ENV '{enabled: false}'
34+
```
35+
36+
To re-enable, either set it back to `{enabled: true}` or remove the variable entirely:
37+
38+
```bash
39+
cf unset-env <app> JBP_CONFIG_JAVA_CF_ENV
40+
```
41+
42+
| Variable | Default | Description |
43+
|----------|---------|-------------|
44+
| `JBP_CONFIG_JAVA_CF_ENV` | `{enabled: true}` | Enable or disable the framework |
45+
46+
Note: if `java-cfenv*.jar` is already present in the application, the buildpack skips injection automatically — no need to disable explicitly for that case.
47+
48+
Disable when:
49+
- The application handles `VCAP_SERVICES` manually with custom binding logic
50+
- The automatic `cloud` profile activation is unwanted
51+
- Another service binding library conflicts with `java-cfenv`

src/java/frameworks/java_cf_env_test.go

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,23 @@ var _ = Describe("Java CF Env", func() {
6868
})
6969
})
7070

71-
Context("with Spring Boot 3.x JAR in lib/", func() {
71+
Context("with Spring Boot 4.1.x JAR in BOOT-INF/lib", func() {
72+
BeforeEach(func() {
73+
Expect(os.MkdirAll(filepath.Join(buildDir, "BOOT-INF", "lib"), 0755)).To(Succeed())
74+
Expect(os.WriteFile(filepath.Join(buildDir, "BOOT-INF", "lib", "spring-boot-4.1.0.jar"), []byte("fake"), 0644)).To(Succeed())
75+
})
76+
77+
It("returns 'Java CF Env'", func() {
78+
name, err := fw.Detect()
79+
Expect(err).NotTo(HaveOccurred())
80+
Expect(name).To(Equal("Java CF Env"))
81+
})
82+
})
83+
84+
Context("with Spring Boot 4.1.x JAR in lib/", func() {
7285
BeforeEach(func() {
7386
Expect(os.MkdirAll(filepath.Join(buildDir, "lib"), 0755)).To(Succeed())
74-
Expect(os.WriteFile(filepath.Join(buildDir, "lib", "spring-boot-3.1.5.jar"), []byte("fake"), 0644)).To(Succeed())
87+
Expect(os.WriteFile(filepath.Join(buildDir, "lib", "spring-boot-4.1.0.jar"), []byte("fake"), 0644)).To(Succeed())
7588
})
7689

7790
It("returns 'Java CF Env'", func() {
@@ -81,10 +94,10 @@ var _ = Describe("Java CF Env", func() {
8194
})
8295
})
8396

84-
Context("with Spring Boot 3.x JAR in WEB-INF/lib", func() {
97+
Context("with Spring Boot 4.1.x JAR in WEB-INF/lib", func() {
8598
BeforeEach(func() {
8699
Expect(os.MkdirAll(filepath.Join(buildDir, "WEB-INF", "lib"), 0755)).To(Succeed())
87-
Expect(os.WriteFile(filepath.Join(buildDir, "WEB-INF", "lib", "spring-boot-3.0.0.jar"), []byte("fake"), 0644)).To(Succeed())
100+
Expect(os.WriteFile(filepath.Join(buildDir, "WEB-INF", "lib", "spring-boot-4.1.0.jar"), []byte("fake"), 0644)).To(Succeed())
88101
})
89102

90103
It("returns 'Java CF Env'", func() {
@@ -94,12 +107,12 @@ var _ = Describe("Java CF Env", func() {
94107
})
95108
})
96109

97-
Context("with Spring-Boot-Version: 3.x in META-INF/MANIFEST.MF", func() {
110+
Context("with Spring-Boot-Version: 4.1.x in META-INF/MANIFEST.MF", func() {
98111
BeforeEach(func() {
99112
Expect(os.MkdirAll(filepath.Join(buildDir, "META-INF"), 0755)).To(Succeed())
100113
Expect(os.WriteFile(
101114
filepath.Join(buildDir, "META-INF", "MANIFEST.MF"),
102-
[]byte("Manifest-Version: 1.0\nSpring-Boot-Version: 3.2.0\nMain-Class: org.springframework.boot.loader.JarLauncher\n"),
115+
[]byte("Manifest-Version: 1.0\nSpring-Boot-Version: 4.1.0\nMain-Class: org.springframework.boot.loader.JarLauncher\n"),
103116
0644,
104117
)).To(Succeed())
105118
})

0 commit comments

Comments
 (0)