This guide provides step-by-step instructions for migrating from the deprecated Spring Auto-reconfiguration framework to java-cfenv.
- Why Migrate?
- What Changes?
- Migration Steps
- Service-Specific Migration
- Testing Your Migration
- Troubleshooting
- Rollback Plan
Spring Auto-reconfiguration is deprecated and disabled by default as of December 2025 because:
- Spring Cloud Connectors (the underlying library) entered maintenance mode in July 2019
- No security updates or bug fixes will be provided
- Not compatible with Spring Boot 3.x
- java-cfenv is the official replacement recommended by Pivotal/VMware
Timeline:
- July 2019: Spring Cloud Connectors deprecated
- December 2025: Spring Auto-reconfiguration disabled by default
- Future: Spring Auto-reconfiguration will be removed entirely
<!-- Automatically added by buildpack - NO CODE CHANGES NEEDED -->
<!-- Automatically reconfigures DataSource, MongoDB, Redis, etc. -->How it worked:
- Buildpack injected
spring-cloud-cloudfoundry-connectorat runtime - Automatically replaced Spring beans with Cloud Foundry-bound services
- No application code changes required
<!-- Add to your pom.xml -->
<dependency>
<groupId>io.pivotal.cfenv</groupId>
<artifactId>java-cfenv-boot</artifactId>
<version>3.1.4</version>
</dependency>How it works:
- You add
java-cfenvdependency to your application - Library reads
VCAP_SERVICESand sets Spring Boot properties - Spring Boot autoconfiguration uses these properties
- More transparent and Spring Boot native
java-cfenv requires Spring Boot 2.1+ (Spring Boot 3.x recommended).
Check your pom.xml or build.gradle:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.2.0</version> <!-- Must be 2.1+ -->
</parent>If you're on Spring Boot 1.x: Upgrade to Spring Boot 2.x or 3.x first.
<dependencies>
<!-- Add this dependency -->
<dependency>
<groupId>io.pivotal.cfenv</groupId>
<artifactId>java-cfenv-boot</artifactId>
<version>3.1.4</version>
</dependency>
</dependencies>dependencies {
implementation 'io.pivotal.cfenv:java-cfenv-boot:3.1.4'
}Note: Check for the latest version at https://github.com/pivotal-cf/java-cfenv
If you previously added Spring Cloud Connectors manually, remove them:
<!-- REMOVE THESE if present -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-spring-service-connector</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-cloudfoundry-connector</artifactId>
</dependency>// REMOVE THESE if present
implementation 'org.springframework.cloud:spring-cloud-spring-service-connector'
implementation 'org.springframework.cloud:spring-cloud-cloudfoundry-connector'If you have custom @Bean configurations for services, you may need to update them.
@Configuration
public class CloudConfig extends AbstractCloudConfig {
@Bean
public DataSource dataSource() {
return connectionFactory().dataSource();
}
}Option 1: Remove custom configuration (let Spring Boot autoconfigure)
// No configuration needed!
// java-cfenv sets spring.datasource.url automatically
// Spring Boot autoconfiguration creates DataSourceOption 2: Keep custom configuration, use environment properties
@Configuration
public class DataSourceConfig {
@Bean
public DataSource dataSource(
@Value("${spring.datasource.url}") String url,
@Value("${spring.datasource.username}") String username,
@Value("${spring.datasource.password}") String password) {
HikariConfig config = new HikariConfig();
config.setJdbcUrl(url);
config.setUsername(username);
config.setPassword(password);
return new HikariDataSource(config);
}
}If you previously enabled Spring Auto-reconfiguration, remove the environment variable:
# Remove this environment variable
cf unset-env my-app JBP_CONFIG_SPRING_AUTO_RECONFIGURATIONOr ensure your manifest.yml doesn't have:
env:
# REMOVE THIS LINE
JBP_CONFIG_SPRING_AUTO_RECONFIGURATION: '{enabled: true}'# Build your application with the new dependency
./mvnw clean package
# Push to Cloud Foundry
cf push my-app
# Check logs to verify java-cfenv is loaded
cf logs my-app --recent | grep java-cf-envYou should see:
Java Buildpack v1.x.x | https://github.com/cloudfoundry/java-buildpack
-----> Supplying frameworks...
java-cf-env=3.1.4
Spring Auto-reconfiguration (automatic):
- Automatically created
DataSourcebean
java-cfenv (automatic):
- Sets
spring.datasource.url,spring.datasource.username,spring.datasource.password - Spring Boot autoconfiguration creates
DataSource
Migration: No code changes needed! Just add the dependency.
Spring Auto-reconfiguration:
// Automatically created MongoClient beanjava-cfenv:
# Automatically sets:
# spring.data.mongodb.uri=mongodb://...Migration: No code changes needed! Spring Boot autoconfiguration handles it.
Spring Auto-reconfiguration:
// Automatically created RedisConnectionFactory beanjava-cfenv:
# Automatically sets:
# spring.data.redis.host=...
# spring.data.redis.port=...
# spring.data.redis.password=...Migration: No code changes needed!
Spring Auto-reconfiguration:
// Automatically created ConnectionFactory beanjava-cfenv:
# Automatically sets:
# spring.rabbitmq.host=...
# spring.rabbitmq.port=...
# spring.rabbitmq.username=...
# spring.rabbitmq.password=...Migration: No code changes needed!
If you're using user-provided services (cf cups), you may need to access them manually.
java-cfenv API:
import io.pivotal.cfenv.core.CfEnv;
import io.pivotal.cfenv.core.CfService;
@Configuration
public class CustomServiceConfig {
@Bean
public MyCustomService customService() {
CfEnv cfEnv = new CfEnv();
CfService service = cfEnv.findServiceByName("my-custom-service");
String url = service.getCredentials().getString("url");
String apiKey = service.getCredentials().getString("api_key");
return new MyCustomService(url, apiKey);
}
}java-cfenv gracefully handles missing VCAP_SERVICES:
# Run locally - uses application.properties
./mvnw spring-boot:runYour local application.properties will be used as normal.
# Push to CF
cf push my-app
# Check that services are bound
cf services
# Verify environment
cf env my-app | grep VCAP_SERVICES
# Check logs for java-cfenv
cf logs my-app --recent | grep "java-cf-env"
# Test application endpoints
curl https://my-app.example.com/healthAdd this debug endpoint to verify connections:
@RestController
public class DebugController {
@Autowired
private DataSource dataSource;
@GetMapping("/debug/datasource")
public String testDataSource() throws Exception {
try (Connection conn = dataSource.getConnection()) {
return "Database connected: " + conn.getMetaData().getURL();
}
}
}Cause: Missing JDBC driver dependency
Solution: Add the appropriate driver:
<!-- PostgreSQL -->
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
</dependency>
<!-- MySQL -->
<dependency>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
</dependency>Cause: Service not bound to application
Solution: Verify service binding:
cf services
cf bind-service my-app my-database
cf restage my-appCause: java-cfenv may not support your service type
Solution: Use the CfEnv API to manually extract credentials:
import io.pivotal.cfenv.core.CfEnv;
@Configuration
public class CustomConfig {
@Bean
public MyService myService() {
CfEnv cfEnv = new CfEnv();
CfService service = cfEnv.findServiceByLabel("my-service-type");
// Extract credentials manually
return new MyService(service.getCredentials());
}
}Cause: java-cfenv only activates "cloud" profile on Cloud Foundry
Solution: This is expected. Locally, the "cloud" profile won't be active.
To test cloud profile locally:
java -jar myapp.jar --spring.profiles.active=cloudIf you encounter issues and need to rollback:
cf set-env my-app JBP_CONFIG_SPRING_AUTO_RECONFIGURATION '{enabled: true}'
cf restage my-appYou can leave java-cfenv in place - it won't conflict with Spring Auto-reconfiguration.
If you encounter migration issues:
- Check buildpack logs:
cf logs my-app --recent - Report issues to: https://github.com/cloudfoundry/java-buildpack/issues
- For java-cfenv issues: https://github.com/pivotal-cf/java-cfenv/issues
- java-cfenv Repository: https://github.com/pivotal-cf/java-cfenv
- java-cfenv Documentation: https://github.com/pivotal-cf/java-cfenv/blob/main/README.md
- Spring Boot on Cloud Foundry: https://docs.spring.io/spring-boot/docs/current/reference/html/deployment.html#deployment.cloud.cloudfoundry
- Cloud Foundry Java Buildpack: https://github.com/cloudfoundry/java-buildpack
- Verify Spring Boot version (2.1+ required, 3.x recommended)
- Add
java-cfenv-bootdependency topom.xmlorbuild.gradle - Remove Spring Cloud Connectors dependencies (if present)
- Review and simplify custom service configurations
- Remove
JBP_CONFIG_SPRING_AUTO_RECONFIGURATIONenvironment variable - Build and test locally
- Deploy to Cloud Foundry
- Verify services are connected
- Test application functionality
- Monitor logs for errors
Migration complete! Your application now uses the modern, supported java-cfenv library.
If you have questions or issues, please consult the java-cfenv documentation or file an issue on the Java Buildpack repository.