Configuration Server

Create config server instance

Spring Cloud Services (SCS) config server tile

Make sure the tile is installed by checking the marketplace

cf marketplace
Getting services from marketplace in org myorg / space development as user...
OK

service                       plans          description
p-config-server               standard       Config Server for Spring Cloud Applications
Git configuration json file

Add this bitbucket/git configuration to a json file to create the service instance. { "git": { "uri": "http://xyz/abc.git", "username": "username", "password": "password", "cloneOnStart": "true", "repos": { "kettering": { "pattern": "amazon*", "uri": "http://xyz/projects/Pivotal Platform/repos/abc" } } }, "count": 3 }

CF CLI command to create config server instance
cf create-service p-config-server standard conf-serv -c config_server.json

p-config-server is the pcf config server tile in marketplace, standard is the plan for the config server (it can be any plan that the tile comes with, usually it is standard), conf-serv - name of the config server instance you are creating that needs to be bound to the application. config_server.json is the json file with the git or svn configuration in the format shown above.

Add this env variable when dealing with non prod installment using Selfsigned certificate
$ cf set-env cook TRUST_CERTS api.cf.wise.com

Setting env variable 'TRUST_CERTS' to 'api.cf.wise.com' for app app-name in org myorg / space development as user...
OK
TIP: Use 'cf restage' to ensure your env variable changes take effect

$ cf restage app-name

Create config files in git

Request Paths

Configuration requests use one of the following path formats:

/{application}/{profile}[/{label}]
/{application}-{profile}.yml
/{label}/{application}-{profile}.yml
/{application}-{profile}.properties
/{label}/{application}-{profile}.properties

A path includes an application, a profile, and optionally a label.

Application:

The name of the application. In a Spring application, this will be derived from spring.application.name or spring.cloud.config.name.

Profile:

The name of a profile, or a comma-separated list of profile names. The Config Server’s concept of a “profile” corresponds directly to that of the Spring Profile.

Label:

The name of a version marker in the configuration source (the repository). This might be a branch name, a tag name, or a Git commit hash. The value given to the Config Server as a default label (the setting of git.label; see the table of the Pivotal Platform Config Server’s general configuration parameters) can be overridden in a client application by setting the spring.cloud.config.label property.

Specify name of the application in bootstrap.yml file
spring:
  application:
    name: app-name

This application will use a path with the application name, so the Config Server will look in its configuration source for files whose names begin with cook, and return configuration properties from those files.

Using multiple profiles

The application will request configurations for any active profiles. To set profiles as active, you can use the SPRINGPROFILESACTIVE environment variable, set for example in manifest.yml.

applications:
  - name: app-name
    host: host-name
    services:
      - config-server
    env:
      SPRING_PROFILES_ACTIVE: production
View Client Application Configuration

Spring Boot Actuator adds an env endpoint to the application and maps it to /env.

This endpoint displays the application’s profiles and property sources from the Spring ConfigurableEnvironment. (See “Endpoints” in the “Spring Boot Actuator” section of the Spring Boot Reference Guide.)

In the case of an application which is bound to a Config Server service instance, env will display properties provided by the instance.

To use Actuator, you must add the spring-boot-starter-actuator dependency to your project. If using Maven, add to pom.xml:

<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
Client to access the configuration
@RefreshScope
@Component
public class Menu {

  @Value("${cook.special}")
  String special;

  public String getSpecial() {
  return special;
}

}

Autowire the configuration class and use it

@RestController
@SpringBootApplication
public class Application {

    @Autowired
    private Menu menu;

    @RequestMapping("/restaurant")
    public String restaurant() {
      return String.format("Today's special is: %s", menu.getSpecial());
    }
}    
Kontakt