1

I am trying to configure spring session backed by hazelcast for spring security oauth2 client application.

I followed below link to configure hazelcast. https://docs.spring.io/spring-session/docs/current/reference/html5/guides/java-hazelcast.html

However, classes annotated with @SpringBootTest started failing due to below error:

java.lang.IncompatibleClassChangeError: class org.springframework.session.hazelcast.PrincipalNameExtractor has interface com.hazelcast.query.extractor.ValueExtractor as super class

My pom.xml of spring boot 2.5 application contain below two new dependencies for hazelcast configuration

       <dependency>
            <groupId>com.hazelcast</groupId>
            <artifactId>hazelcast</artifactId>
            <version>4.2</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.session</groupId>
            <artifactId>spring-session-hazelcast</artifactId>
        </dependency>

As per below stackoverflow post , issue seems to be that ValueExtractor is available for two different versions in maven dependencies IncompatibleClassChangeError: class ClassMetadataReadingVisitor has interface ClassVisitor as super class

Hence, I checked maven dependencies and can see that PrincipalNameExtractor is available from 2.5 version of spring-session-hazelcast while ValueExtractor is available from 4.2 version on com.hazelcast. However, spring-session-hazelcast is using 3.12.12 version of com.hazelcast for compilation.

So should I use 3.12.12 version of com.hazelcast to resolve this issue or am in misinterpreting the issue? I prefer to use latest version.

user2800089
  • 2,015
  • 6
  • 26
  • 47
  • 1
    starting from v2.4.0, you can use Hazelcast v4.x with Hazelcast4PrincipalNameExtractor and Hazelcast4IndexedSessionRepository. Here is a guide covering both versions: https://guides.hazelcast.org/spring-session-hazelcast – ozcan May 27 '21 at 12:04
  • @ozcan Thanks for the post. This post resolved all maven dependencies & fixed all failing testcases. – user2800089 May 27 '21 at 12:55
  • good to hear that worked. Posting as an answer also to make it visible. – ozcan May 27 '21 at 15:37
  • @Ozcan could you plz also share any link which shows the configuration changes required to make hazelcast work with spring oauth2 client and spring security 5 – user2800089 May 27 '21 at 17:25

1 Answers1

1

Starting from spring-sessions v2.4.0, you can use Hazelcast v4.x with configuring Hazelcast4PrincipalNameExtractor and Hazelcast4IndexedSessionRepository for the session repository. The only difference is the class names with 4 indicator. That is, HazelcastIndexedSessionRepository becomes 4.x compatible with Hazelcast4IndexedSessionRepository.

Here is a guide covering both versions: https://guides.hazelcast.org/spring-session-hazelcast/

ozcan
  • 335
  • 2
  • 7