eBook – Guide Spring Cloud – NPI EA (cat=Spring Cloud)
announcement - icon

Let's get started with a Microservice Architecture with Spring Cloud:

>> Join Pro and download the eBook

eBook – Mockito – NPI EA (tag = Mockito)
announcement - icon

Mocking is an essential part of unit testing, and the Mockito library makes it easy to write clean and intuitive unit tests for your Java code.

Get started with mocking and improve your application tests using our Mockito guide:

Download the eBook

eBook – Java Concurrency – NPI EA (cat=Java Concurrency)
announcement - icon

Handling concurrency in an application can be a tricky process with many potential pitfalls. A solid grasp of the fundamentals will go a long way to help minimize these issues.

Get started with understanding multi-threaded applications with our Java Concurrency guide:

>> Download the eBook

eBook – Reactive – NPI EA (cat=Reactive)
announcement - icon

Spring 5 added support for reactive programming with the Spring WebFlux module, which has been improved upon ever since. Get started with the Reactor project basics and reactive programming in Spring Boot:

>> Join Pro and download the eBook

eBook – Java Streams – NPI EA (cat=Java Streams)
announcement - icon

Since its introduction in Java 8, the Stream API has become a staple of Java development. The basic operations like iterating, filtering, mapping sequences of elements are deceptively simple to use.

But these can also be overused and fall into some common pitfalls.

To get a better understanding on how Streams work and how to combine them with other language features, check out our guide to Java Streams:

>> Join Pro and download the eBook

eBook – Jackson – NPI EA (cat=Jackson)
announcement - icon

Do JSON right with Jackson

Download the E-book

eBook – HTTP Client – NPI EA (cat=Http Client-Side)
announcement - icon

Get the most out of the Apache HTTP Client

Download the E-book

eBook – Maven – NPI EA (cat = Maven)
announcement - icon

Get Started with Apache Maven:

Download the E-book

eBook – Persistence – NPI EA (cat=Persistence)
announcement - icon

Working on getting your persistence layer right with Spring?

Explore the eBook

eBook – RwS – NPI EA (cat=Spring MVC)
announcement - icon

Building a REST API with Spring?

Download the E-book

Course – LS – NPI EA (cat=Jackson)
announcement - icon

Get started with Spring and Spring Boot, through the Learn Spring course:

>> LEARN SPRING
Course – RWSB – NPI EA (cat=REST)
announcement - icon

Explore Spring Boot 3 and Spring 6 in-depth through building a full REST API with the framework:

>> The New “REST With Spring Boot”

Course – LSS – NPI EA (cat=Spring Security)
announcement - icon

Yes, Spring Security can be complex, from the more advanced functionality within the Core to the deep OAuth support in the framework.

I built the security material as two full courses - Core and OAuth, to get practical with these more complex scenarios. We explore when and how to use each feature and code through it on the backing project.

You can explore the course here:

>> Learn Spring Security

Course – LSD – NPI EA (tag=Spring Data JPA)
announcement - icon

Spring Data JPA is a great way to handle the complexity of JPA with the powerful simplicity of Spring Boot.

Get started with Spring Data JPA through the guided reference course:

>> CHECK OUT THE COURSE

Partner – Moderne – NPI EA (cat=Spring Boot)
announcement - icon

Refactor Java code safely — and automatically — with OpenRewrite.

Refactoring big codebases by hand is slow, risky, and easy to put off. That’s where OpenRewrite comes in. The open-source framework for large-scale, automated code transformations helps teams modernize safely and consistently.

Each month, the creators and maintainers of OpenRewrite at Moderne run live, hands-on training sessions — one for newcomers and one for experienced users. You’ll see how recipes work, how to apply them across projects, and how to modernize code with confidence.

Join the next session, bring your questions, and learn how to automate the kind of work that usually eats your sprint time.

Course – Summer Sale 2026 – NPI EA (cat= Baeldung)
announcement - icon

Yes, we're now running our only Summer Sale. All Courses are 30% off until 20th July, 2026:

>> EXPLORE ACCESS NOW

Course – Summer Sale 2026 – NPI (cat=Baeldung)
announcement - icon

Yes, we're now running our only Summer Sale. All Courses are 30% off until 20th July, 2026:

>> EXPLORE ACCESS NOW

1. Overview

Deploying a Spring Boot application to Cloud Foundry is a simple exercise. In this tutorial, we’ll show you how to do it.

2. Spring Cloud Dependencies

Since this project will require new dependencies for Spring Cloud project, we’ll add the Spring Cloud Dependencies BOM:

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-dependencies</artifactId>
            <version>2023.0.0</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

We can find the latest version of the spring-cloud-dependencies library on Maven Central.

Now, we want to maintain a separate build for the Cloud Foundry, so we’ll create a profile named cloudfoundry in the Maven pom.xml.

We’ll also add compiler exclusions and the Spring Boot plugin to configure the name of the package:

<build>
    <resources>
        <resource>
            <directory>src/main/resources</directory>
            <excludes>
                <exclude>**/logback.xml</exclude>
            </excludes>
        </resource>
    </resources>
    <plugins>
        <plugin>                        
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <configuration>
                <finalName>${project.name}-cf</finalName>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <excludes>
                    <exclude>**/cloud/config/*.java</exclude>
                </excludes>
            </configuration>
        </plugin>
    </plugins>
</build>

We also want to exclude the cloud-specific files from the normal build so we add a global profile exclusion to Maven compiler plugin:

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <excludes>
                    <exclude>**/cloud/*.java</exclude>
                </excludes>
            </configuration>
        </plugin>
    </plugins>
</build>

Then, we need to add the Spring Cloud Starter and the Spring Cloud Connectors libraries, which provide support for Cloud Foundry:

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter</artifactId>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-cloud-connectors</artifactId>
</dependency>

3. Cloud Foundry Configuration

To go through this tutorial, we need to register for a trial here or download the pre-configured development environment for Native Linux or Virtual Box.

Furthermore, the Cloud Foundry CLI needs to be installed. Instructions are here.

After registration with a Cloud Foundry provider, the API URL will be made available (you can come back to it by following the Tools option on the left side).

The application container allows us to bind services to applications. Next, let’s log in to the Cloud Foundry environment:

cf login -a <url>

The Cloud Foundry Marketplace is a catalog of services like databases, messaging, email, monitoring, logging and a lot more. Most services provide a free or trial plan.

Let’s search the Marketplace for “MySQL” and create a service for our application:

cf marketplace | grep MySQL
>
cleardb     spark, boost*, amp*, shock*         Highly available MySQL for your Apps.

The output lists the services with “MySQL” in the description. On PCF the MySQL service is named cleardb and non-free plans are marked with an asterisk.

Next, we list the details of a service using:

cf marketplace -s cleardb
>
service plan description                                                                 free or paid
spark        Great for getting started and developing your apps                             free
boost        Best for light production or staging your applications                         paid
amp          For apps with moderate data requirements                                       paid
shock        Designed for apps where you need real MySQL reliability, power and throughput  paid

Now we create a free MySQL service instance named spring-bootstrap-db:

cf create-service cleardb spark spring-bootstrap-db

4. Application Configuration

Next, we add a @Configuration annotated class that extends AbstractCloudConfig to create a DataSource in the package named org.baeldung.cloud.config:

@Configuration
@Profile("cloud")
public class CloudDataSourceConfig extends AbstractCloudConfig {
 
    @Bean
    public DataSource dataSource() {
        return connectionFactory().dataSource();
    }
}

Adding @Profile(“cloud”) ensures that the Cloud Connector isn’t active when we do local testing. We also add @ActiveProfiles(profiles = {“local”}) to the Integration tests.

Then build the application with:

mvn clean install spring-boot:repackage -P cloudfoundry

Also, we need to provide a manifest.yml file, to bind the service to the application.

We usually place the manifest.yml file in the project folder but in this case, we’ll create a cloudfoundry folder since we’re going to demonstrate deploying to multiple cloud-native providers:

---
applications:
- name: spring-boot-bootstrap
  memory: 768M
  random-route: true
  path: ../target/spring-boot-bootstrap-cf.jar
  env:
    SPRING_PROFILES_ACTIVE: cloud,mysql
  services:
  - spring-bootstrap-db

5. Deployment

Deploying the application is now as easy as:

cd cloudfoundry
cf push

Cloud Foundry will use the Java buildpack to deploy the application and create a random route to the application.

We can view the last few entries in the log file using:

cf logs spring-boot-bootstrap --recent

Or we can tail the log file:

cf logs spring-boot-bootstrap

Finally, we need the route name to test the application:

cf app spring-boot-bootstrap
>
name:              spring-boot-bootstrap
requested state:   started
routes:            spring-boot-bootstrap-delightful-chimpanzee.cfapps.io
last uploaded:     Thu 23 Aug 08:57:20 SAST 2018
stack:             cflinuxfs2
buildpacks:        java-buildpack=v4.15-offline-...

type:           web
instances:      1/1
memory usage:   768M
     state     since                  cpu    memory           disk
#0   running   2018-08-23T06:57:57Z   0.5%   290.9M of 768M   164.7M of 1G

Executing the following command will add a new book:

curl -i --request POST \
    --header "Content-Type: application/json" \
    --data '{"title": "The Player of Games", "author": "Iain M. Banks"}' \
    https://<app-route>/api/books
#OR
http POST https://<app-route>/api/books title="The Player of Games" author="Iain M. Banks"

And this command will list all books:

curl -i https://<app-route>/api/books 
#OR 
http https://<app-route>/api/books
>
HTTP/1.1 200 OK

[
    {
        "author": "Iain M. Banks",
        "id": 1,
        "title": "Player of Games"
    },
    {
        "author": "J.R.R. Tolkien",
        "id": 2,
        "title": "The Hobbit"
    }
]

6. Scaling the Application

Lastly, scaling an application on Cloud Foundry is as simple as using the scale command:

cf scale spring-cloud-bootstrap-cloudfoundry <options>
Options:
-i <instances>
-m <memory-allocated> # Like 512M or 1G
-k <disk-space-allocated> # Like 1G or 2G
-f # Force restart without prompt

Remember to delete the application when we don’t need it anymore:

cf delete spring-cloud-bootstrap-cloudfoundry

7. Conclusion

In this article, we covered the Spring Cloud libraries that simplify the development of a cloud-native application using Spring Boot. Deployment with the Cloud Foundry CLI is well documented here.

Extra plugins for the CLI are available in the plugin repository.

The code backing this article is available on GitHub. Once you're logged in as a Baeldung Pro Member, start learning and coding on the project.
Baeldung Pro – NPI EA (cat = Baeldung)
announcement - icon

Baeldung Pro comes with both absolutely No-Ads as well as finally with Dark Mode, for a clean learning experience:

>> Explore a clean Baeldung

Once the early-adopter seats are all used, the price will go up and stay at $33/year.

eBook – HTTP Client – NPI EA (cat=HTTP Client-Side)
announcement - icon

The Apache HTTP Client is a very robust library, suitable for both simple and advanced use cases when testing HTTP endpoints. Check out our guide covering basic request and response handling, as well as security, cookies, timeouts, and more:

>> Download the eBook

eBook – Java Concurrency – NPI EA (cat=Java Concurrency)
announcement - icon

Handling concurrency in an application can be a tricky process with many potential pitfalls. A solid grasp of the fundamentals will go a long way to help minimize these issues.

Get started with understanding multi-threaded applications with our Java Concurrency guide:

>> Download the eBook

eBook – Java Streams – NPI EA (cat=Java Streams)
announcement - icon

Since its introduction in Java 8, the Stream API has become a staple of Java development. The basic operations like iterating, filtering, mapping sequences of elements are deceptively simple to use.

But these can also be overused and fall into some common pitfalls.

To get a better understanding on how Streams work and how to combine them with other language features, check out our guide to Java Streams:

>> Join Pro and download the eBook

eBook – Persistence – NPI EA (cat=Persistence)
announcement - icon

Working on getting your persistence layer right with Spring?

Explore the eBook

Course – LS – NPI EA (cat=REST)

announcement - icon

Get started with Spring Boot and with core Spring, through the Learn Spring course:

>> CHECK OUT THE COURSE

Partner – Moderne – NPI EA (tag=Refactoring)
announcement - icon

Modern Java teams move fast — but codebases don’t always keep up. Frameworks change, dependencies drift, and tech debt builds until it starts to drag on delivery. OpenRewrite was built to fix that: an open-source refactoring engine that automates repetitive code changes while keeping developer intent intact.

The monthly training series, led by the creators and maintainers of OpenRewrite at Moderne, walks through real-world migrations and modernization patterns. Whether you’re new to recipes or ready to write your own, you’ll learn practical ways to refactor safely and at scale.

If you’ve ever wished refactoring felt as natural — and as fast — as writing code, this is a good place to start.

Course – Summer Sale 2026 – NPI EA (cat= Baeldung)
announcement - icon

Yes, we're now running our only Summer Sale. All Courses are 30% off until 20th July, 2026:

>> EXPLORE ACCESS NOW

Course – Summer Sale 2026 – NPI (All)
announcement - icon

Yes, we're now running our only Summer Sale. All Courses are 30% off until 20th July, 2026:

>> EXPLORE ACCESS NOW

eBook Jackson – NPI EA – 3 (cat = Jackson)
eBook – eBook Guide Spring Cloud – NPI (cat=Cloud/Spring Cloud)