Spring Boot GemFire Pivotal Cloud Cache @EnableClusterAware and ClientCacheRegionFactory

157 Views Asked by At

Im trying to connect to Pivotal Cloud Cache server Regions.

I'm using @EnableClusterAware and trying to configure the client Regions via ClientRegionFactoryBean as below:

@Bean("clientRegion")
ClientRegionFactoryBean someClientRegion(GemFireCache gemfire) {
   // ...
}

Either GemFireCache or ClientCache beans are not available with the annotation @EnableClusterAware. It's available only with @ClientCacheApplication.

Is there any annotations that needs to be used in conjunction with @EnableClusterAware so that GemFireCache gets injected?

Please help.

1

There are 1 best solutions below

1
On

When Spring Boot for Apache Geode, or alternatively GemFire, (SBDG) is on the classpath of your Spring Boot application (see here), then SBDG auto-configuration will automatically create and configure a ClientCache instance for you (see here).

TIP: You can also review the Getting Stated Sample Guide and Source to see this behavior in action, for yourself. The Guide also talks about the use of the @EnableClusterAware annotation, here.

The @EnableClusterAware annotation is simply a development-time, SBDG annotation that enables you to switch between environments (e.g. local vs. managed, such as when pushing your Spring Boot application up to run in PCF, connected to PCC, and then testing locally in your IDE) without having to change any configuration (hence the goals).

The @EnableClusterAware annotation does not create any GemFire/Geode cache instances for you. Only SBDG's auto-configuration, or declaring an explicit SDG annotation (e.g. @ClientCacheApplication) will do that for you. Still, when using SBDG auto-configuration, you do not need an explicit SDG cache application annotation, like @ClientCacheApplication, since SBDG auto-configuration (again) creates and configures a ClientCache instance by default.

TIP: See the documentation on the @EnableClusterAware annotation for more details.

If ClientCache is not provided (auto-configured), then you are not:

  1. Using SBDG, or rather do not have SBDG on the Spring Boot application classpath (see here)
  2. Have not bootstrapped or configured and ran your Spring application with Spring Boot
  3. Your Spring Boot application configuration is incorrect
  4. You have explicitly disabled or overrode the SBDG auto-configuration
  5. Etc.

One or more of these have to be true.