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 Cloud Foundry variables such as VCAP_SERVICES, allowing Spring Boot's autoconfiguration to kick in.
This is the recommended replacement for Spring AutoReconfiguration library which is deprecated. See the java-cfenv repository for more details.
The cloud Spring profile is activated at runtime by java-cfenv's CloudProfileApplicationListener, which ships in the java-cfenv-all module. To ensure the profile is active — or to activate it independently of java-cfenv — set it explicitly. Use SPRING_PROFILES_INCLUDE=cloud to add cloud alongside any other active profiles, or SPRING_PROFILES_ACTIVE=cloud to set it as the sole active profile (this replaces any others). The buildpack itself does not set any Spring profile.
The buildpack selects the appropriate java-cfenv version based on the detected Spring Boot major version:
| Spring Boot | java-cfenv |
|---|---|
| 3.x | 3.x (latest) |
| 4.x | 4.x (latest) |
| Detection Criterion | Existence of a spring-boot-3.*.jar or spring-boot-4.*.jar in BOOT-INF/lib, WEB-INF/lib, or lib/; or a Spring-Boot-Version: 3.* / Spring-Boot-Version: 4.* entry in META-INF/MANIFEST.MF | No existing java-cfenv library found in the application |
| Tags | java-cf-env=<version> |
The framework is implemented in src/java/frameworks/java_cf_env.go:
- Detect — activates only when all of these hold: the framework is enabled (see Configuration); a Spring Boot 3.x or 4.x marker is found (a
spring-boot-{3,4}.*.jarunderBOOT-INF/lib,WEB-INF/lib, orlib/, or aSpring-Boot-Version: 3.*/4.*entry inMETA-INF/MANIFEST.MF); and the application does not already bundle ajava-cfenv*.jar(if it does, the buildpack backs off and uses the application's own copy). - Supply — selects the java-cfenv version from the detected Spring Boot major (Spring Boot 3 → the manifest's
3.xline, Spring Boot 4 → the4.xline) and installs thejava-cfenv-alljar into the dependency directory. - Finalize — appends the installed jar to
CLASSPATHvia a.profile.d/java_cf_env.shscript, so it is on the application's runtime classpath. - Runtime — Spring Boot reads the jar's
META-INF/spring.factories: theEnvironmentPostProcessors mapVCAP_SERVICESto Spring properties, andCloudProfileApplicationListener(in thejava-cfenv-allmodule) activates thecloudprofile when running in Cloud Foundry.
The framework can be disabled via the JBP_CONFIG_JAVA_CF_ENV environment variable:
cf set-env <app> JBP_CONFIG_JAVA_CF_ENV '{enabled: false}'
cf restage <app>The buildpack only re-reads this variable during staging, so a cf restage is required for the change to take effect.
To re-enable, either set it back to {enabled: true} or remove the variable entirely:
cf unset-env <app> JBP_CONFIG_JAVA_CF_ENV
cf restage <app>| Variable | Default | Description |
|---|---|---|
JBP_CONFIG_JAVA_CF_ENV |
{enabled: true} |
Enable or disable the framework |
Note: if java-cfenv*.jar is already present in the application, the buildpack skips injection automatically — no need to disable explicitly for that case.
Disable when:
- The application handles
VCAP_SERVICESmanually with custom binding logic - The automatic
cloudprofile activation is unwanted - Another service binding library conflicts with
java-cfenv
{enabled: false} disables the whole framework — both the VCAP_SERVICES → Spring property mapping and the cloud profile activation. There is no option to disable only the cloud profile.
For finer control, bundle a java-cfenv artifact in the application yourself. Because the buildpack backs off whenever a java-cfenv*.jar is already present, the app's choice wins:
| App bundles | Property mapping | cloud profile |
|---|---|---|
(nothing — buildpack injects java-cfenv-all) |
yes | yes |
java-cfenv-all |
yes | yes (app pins the version) |
java-cfenv-boot |
yes | no (no CloudProfileApplicationListener) |
java-cfenv (core) |
no (API only) | no |
So an app can include java-cfenv-boot to keep property mapping without the cloud profile, or the bare java-cfenv core to opt out of all automatic behaviour and use the CfEnv API directly.