Spring Config Integration With a PCF Application: A Step-by-Step Guide

Why Spring Configuration? 

Spring Cloud Config provides support for externalized configuration in a distributed system. It allows you to dynamically push updates to configuration properties to the application without needing to restart or redeploy.

Step-by-Step Guide to Integrate With a PCF Application

Step 1: Add a Maven Dependency

XML
 




xxxxxxxxxx
1
23


 
1
<dependency>
2

          
3
               <groupId>io.pivotal.spring.cloud</groupId>
4

          
5
<artifactId>spring-cloud-services-starter-config-client</artifactId>
6

          
7
             </dependency>
8

          
9
              <dependency>
10

          
11
                    <groupId>org.springframework.cloud</groupId>
12

          
13
                    <artifactId>spring-cloud-starter-config</artifactId>
14

          
15
             </dependency>
16

          
17
             <dependency>
18

          
19
                    <groupId>org.springframework.boot</groupId>
20

          
21
                    <artifactId>spring-boot-starter-actuator</artifactId>
22

          
23
             </dependency>


pom.xml 

XML
 






Step 2: Add refreshscope and EnableAutoConfiguration to the Model Class

Java
 




x


1
package gsahoo.demo.model;
2

          
3
import org.springframework.beans.factory.annotation.Value;
4
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
5
import org.springframework.cloud.context.config.annotation.RefreshScope;
6
import org.springframework.context.annotation.Configuration;
7
import org.springframework.stereotype.Component;
8

          
9
@Configuration
10

          
11
@EnableAutoConfiguration
12

          
13
@RefreshScope
14

          
15
@Component
16

          
17
public class Person {
18

          
19
    @Value("${person.company}")
20

          
21
    String company = null;
22

          
23
    public void setCompany(String company) {
24

          
25
        this.company = company;
26

          
27
    }
28

          
29
    public String getCompany() {
30

          
31
        return company;
32

          
33
    }
34

          
35
}


If you are autowiring this model object in any other class then make sure to add refreshscope to that class as well.

PCF 2.6 Feature – App Revisions

Overview

Developers, who have been using Pivotal Cloud Foundry (PCF) have been asking the question of how they know which version of Application PCF is running. We used to check this in on-premise by going to that VM and checking the jar version. Also, performing a rollback smoothly for PCF deployments at the SCM (Github) or CI/CD level is painful and risk-prone. It involves verification, approval and other deployment processes.

With PCF 2.6, Pivotal has come up with a feature called App Revisions. Using this feature, we can rollback the deployment for an application very easily. In this article, we will try to understand this feature and walk through the steps for rollback.

Running Spring Batch Applications in PCF

1. Overview

Most developers are creating microservices these days and deploying to cloud platforms. Pivotal Cloud Foundry (PCF) is one of the most well known cloud platforms. When we talk about deploying applications on PCF, mostly they would be long-running processes which never end, like web applications, SPAs, or REST-based services. PCF monitors all these long-running instances and if one goes down it spins up the new instance to replace the failed one. This works fine where the process is expected to run continuously but for a batch process, it's overkill. The container will be running all the time with no CPU usage and the cost will add up. Many developers have an ambiguity that PCF cannot run a batch application which can just be initiated based on a request. But that is not correct.

Spring Batch enables us to create a batch application and provides many out-of-the-box features to reduce boilerplate code. Recently, Spring Cloud Task has been added in the list of projects to create short-running processes. With both of these options, we can create microservices, deploy them on PCF, and then stop them so that PCF doesn't try to self heal them. And with the help of PCF Scheduler, we can schedule the task to run them at a certain time of the day. Let's see in this article how we can do that with very few steps.

Angular 7 + Spring Boot Application: Hello World Example

In this tutorial, we will create a full-stack application where we expose an endpoint using Spring Boot and consume this endpoint using Angular 7 and display the data. In the next tutorial, we will be further enhancing this application and performing CRUD operations.

Previously, we have seen what a PCF is and how to deploy an application to PCF. I have deployed this application we are developing to PCF. The demo application is as follows-