VMware GemFire

 SpringBoot 2/Pivotal data Gemfire application issues

Amar Das's profile image
Amar Das posted May 02, 2019 06:05 PM

Hi,

 

I am building a test application using SpringBoot2 and Pivotal Data Gemfire. The main application code looks like below

@SpringBootApplication @ClientCacheApplication(locators = { @ClientCacheApplication.Locator(host = "myhost", port = 10334) }) @EnableEntityDefinedRegions(basePackageClasses = Person.class, clientRegionShortcut = ClientRegionShortcut.PROXY) @EnableGemfireRepositories public class GemfiretestApplication { public static void main(String[] args) { SpringApplication.run(GemfiretestApplication.class, args); }   ...

My build.gradle

plugins { id 'org.springframework.boot' version '2.1.4.RELEASE' id 'java' }   apply plugin: 'io.spring.dependency-management'   group = 'com.example' version = '0.0.1-SNAPSHOT'   sourceCompatibility = 1.8 targetCompatibility = 1.8   repositories { mavenCentral() maven { url "https://repo.spring.io/libs-release" } }   dependencies { implementation 'org.springframework.boot:spring-boot-starter-actuator' implementation 'org.springframework.boot:spring-boot-starter-web' implementation 'org.springframework.data:spring-data-gemfire:2.1.6.RELEASE' compileOnly 'org.projectlombok:lombok' annotationProcessor 'org.projectlombok:lombok'   testImplementation 'org.springframework.boot:spring-boot-starter-test' }

While running I get the following error

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'gemfireCache': FactoryBean threw exception on object creation; nested exception is java.lang.ExceptionInInitializerError at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:178) at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.getObjectFromFactoryBean(FactoryBeanRegistrySupport.java:101) at org.springframework.beans.factory.support.AbstractBeanFactory.getObjectForBeanInstance(AbstractBeanFactory.java:1674) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.getObjectForBeanInstance(AbstractAutowireCapableBeanFactory.java:1249) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:257) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:367) ... 95 more Caused by: java.lang.ExceptionInInitializerError at org.apache.geode.internal.cache.GemFireCacheImpl.<clinit>(GemFireCacheImpl.java:255) at org.apache.geode.cache.client.ClientCacheFactory.getAnyInstance(ClientCacheFactory.java:626) at java.util.Optional.orElseGet(Optional.java:267) at org.springframework.data.gemfire.client.ClientCacheFactoryBean.fetchCache(ClientCacheFactoryBean.java:172) at org.springframework.data.gemfire.CacheFactoryBean.resolveCache(CacheFactoryBean.java:316) at org.springframework.data.gemfire.CacheFactoryBean.init(CacheFactoryBean.java:268) at java.util.Optional.orElseGet(Optional.java:267) at org.springframework.data.gemfire.CacheFactoryBean.getObject(CacheFactoryBean.java:795) at org.springframework.data.gemfire.CacheFactoryBean.getObject(CacheFactoryBean.java:108) at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:171)

Anyone has a clue? Is it because some mismatch between library version? Or I need more configuration etc.

Juan Cassella's profile image
Juan Cassella

Hello Amat,

 

Thanks for contacting the Pivotal Support Community!!.

My name is Juan José Ramos Cassella, and I am a GemFire Technical Support Engineer with Pivotal.

That said, I've tested this setup locally and found out that the most important part of the stack trace (which is actually what tells you what's happening!!) was omitted in your post:

Caused by: java.lang.ClassCastException: org.apache.logging.slf4j.SLF4JLogger cannot be cast to org.apache.logging.log4j.core.Logger at org.apache.geode.internal.logging.LogService.init(LogService.java:82) ~[geode-core-9.5.3.jar:na] at org.apache.geode.internal.logging.LogService.<clinit>(LogService.java:73) ~[geode-core-9.5.3.jar:na] ... 41 common frames omitted

That said, and as a summary, the problem is that Pivotal GemFire 9.5.3 (transitive dependency pulled through spring-data-gemfire 2.1.6) uses an out of date dependency on Log4j [1], where newer versions of Spring Boot [2] (2.0 onwards) pull in a more recent version of the same library, causing these weird exceptions in runtime.

In order to solve the problem, you basically have three options:

  1. Upgrade your Pivotal GemFire version to the latest available release 9.7.0, which has an updated Log4j version as well. Please have a look at Spring Data for Pivotal GemFire Version Compatibility Matrix [3] to make sure you're using a fully supported combination.
  2. Simply exclude the org.springframework.boot:spring-boot-starter-logging dependency all together from your project, which will avoid any sort of logging issues with older, incompatible versions.
  3. Exclude org.apache.logging.log4j.log4j-to-slf4j dependency directly, technically that's the one causing the issue.

 

As a side note, you might want to have a look at the newest and greatest Spring Boot for Apache Geode & Pivotal GemFire [4], it greatly simplifies the integration between Spring Boot and Apache Geode / Pivotal GemFire (just to mention one of the cool things it provides).

Hope this helps.

Cheers.

 

[1]: https://logging.apache.org/log4j

[2]: https://spring.io/projects/spring-boot

[3]: https://github.com/spring-projects/spring-data-gemfire/wiki/Spring-Data-for-Pivotal-GemFire-Version-Compatibility-Matrix

[4]: https://docs.spring.io/autorepo/docs/spring-boot-data-geode-build/1.0.0.RC2/reference/html5/index.html

Amar Das's profile image
Amar Das

Thanks Juan. I have reviewed the compatibility matrix and updated my project. Gradle can't find spring-data-gemfire:2.2.0.M3. I checked MavenCentral. 2.2.0.M3 is not there. Where can I find it?

 

Amar

Juan Cassella's profile image
Juan Cassella

Hello Amar,

 

What do you mean "it is not there"?, I can see it just fine in the Maven Repository [1].

Moreover, I've tried locally to add the following to my build.gradle file and the dependency is correctly downloaded:

compile("org.springframework.data:spring-data-gemfire:2.2.0.M3")

Maybe you have a type somewhere?.

Cheers.

 

[1]: https://mvnrepository.com/artifact/org.springframework.data/spring-data-gemfire/2.2.0.M3

Amar Das's profile image
Amar Das

I have to add maven { url "https://repository.jboss.org/nexus/content/repositories/public/" } to get the library (2.2.0.M3). It still produces the same error. They I added this configuration to my build file, which finally fixed the build issue.

 

configurations { compile.exclude module: 'spring-boot-starter-logging' }

Thank you.

 

 

Juan Cassella's profile image
Juan Cassella

Hello Amar,

 

Perfect, thanks for the update!.

Cheers.