This topic discusses externalized configuration of Spring Boot for VMware GemFire.

Like Spring Boot, Spring Boot for VMware GemFire supports externalized configuration. For more information about Spring Boot, see the Spring Boot documentation.

Externalized configuration is configuration metadata stored in Spring Boot application.properties. You can separate concerns by addressing each concern in an individual properties file. Optionally, you can enable any specific property file for only a specific profile. For more information about Spring Boot profiles, see profile in the Spring Boot documentation.

You can do many other powerful things, such as using placeholders in properties, encrypting properties, and so on.

This topic focuses particularly on type safety.

Like Spring Boot, Spring Boot for VMware GemFire provides a hierarchy of classes that captures configuration for several VMware GemFire features in an associated @ConfigurationProperties annotated class. Again, the configuration metadata is specified as well-known, documented properties in one or more Spring Boot application.properties files.

For instance, a Spring Boot, VMware GemFire ClientCache application might be configured as follows:

Example 1. Spring Boot application.properties containing Spring Data properties for VMware GemFire

# Spring Boot application.properties used to configure VMware GemFire

spring.data.gemfire.name=MySpringBootGemFireApplication

# Configure general cache properties
spring.data.gemfire.cache.copy-on-read=true
spring.data.gemfire.cache.log-level=debug

# Configure ClientCache specific properties
spring.data.gemfire.cache.client.durable-client-id=123
spring.data.gemfire.cache.client.keep-alive=true

# Configure a log file
spring.data.gemfire.logging.log-file=/path/to/geode.log

# Configure the client's connection Pool to the servers in the cluster
spring.data.gemfire.pool.locators=10.105.120.16[11235],boombox[10334]

You may sometimes require access to the configuration metadata (specified in properties) in your Spring Boot applications themselves, perhaps to further inspect or act on a particular configuration setting. You can access any property by using Spring’s Environment abstraction:

Example 2. Using the Spring Environment

@Configuration
class GemFireConfiguration {

    void readConfigurationFromEnvironment(Environment environment) {
        boolean copyOnRead = environment.getProperty("spring.data.gemfire.cache.copy-on-read",
            Boolean.TYPE, false);
    }
}

While using Environment is a nice approach, you might need access to additional properties or want to access the property values in a type-safe manner. Therefore, you can now, thanks to Spring Boot for VMware GemFire’s auto-configured configuration processor, access the configuration metadata by using @ConfigurationProperties classes.

To add to the preceding example, you can now do the following:

Example 3. Using GemFireProperties

@Component
class MyApplicationComponent {

    @Autowired
    private GemFireProperties gemfireProperties;

    public void someMethodUsingGemFireProperties() {

        boolean copyOnRead = this.gemfireProperties.getCache().isCopyOnRead();

        // do something with `copyOnRead`
    }
}

Given a handle to GemFireProperties, you can access any of the configuration properties that are used to configure VMware GemFire in a Spring context. You need only autowire an instance of GemFireProperties into your application component.

Externalized Configuration of Spring Session

You can access the externalized configuration of Spring Session when you use VMware GemFire as your (HTTP) session state caching provider.

In this case, you need only acquire a reference to an instance of the SpringSessionPropertiesclass.

As shown earlier in this chapter, you can specify Spring Session for VMware GemFire properties as follows:

Example 4. Spring Boot application.properties for Spring Session using VMware GemFire as the (HTTP) session state caching provider

# Spring Boot application.properties used to configure VMware GemFire as a (HTTP) session state caching provider
# in Spring Session

spring.session.data.gemfire.session.expiration.max-inactive-interval-seconds=300
spring.session.data.gemfire.session.region.name=UserSessions

Then, in your application, you can do something similar to the following example:

Example 5. Using SpringSessionProperties

@Component
class MyApplicationComponent {

    @Autowired
    private SpringSessionProperties springSessionProperties;

    public void someMethodUsingSpringSessionProperties() {

        String sessionRegionName = this.springSessionProperties
            .getSession().getRegion().getName();

        // do something with `sessionRegionName`
    }
}
check-circle-line exclamation-circle-line close-line
Scroll to top icon