spring boot hazelcast session storing ClassNotFoundException

343 views
Skip to first unread message

Валентин Твардовский

unread,
Apr 7, 2021, 8:00:59 AM4/7/21
to Hazelcast
Hello :)

I'm trying to configure Hazelcast Client/Server topology to be able to store spring session in hazelcast. 

I have a server with such configs

@Configuration
@EnableHazelcastHttpSession
public class HazelcastServerConfiguration {

@Bean
public Config hazelCastConfig() {
Config config = new Config();

config.getMapConfig(HazelcastIndexedSessionRepository.DEFAULT_SESSION_MAP_NAME)
.addMapAttributeConfig(springSessionAttributeConfig())
.addMapIndexConfig(springSessionIndexConfig());

SerializerConfig serializerConfig = new SerializerConfig();
serializerConfig.setImplementation(new HazelcastSessionSerializer()).setTypeClass(MapSession.class);
config.getSerializationConfig().addSerializerConfig(serializerConfig);

return config;
}

@Bean
public HazelcastInstance hazelcastInstance(Config config) {
return Hazelcast.newHazelcastInstance(config);
}

private MapAttributeConfig springSessionAttributeConfig() {
return new MapAttributeConfig()
.setName(HazelcastIndexedSessionRepository.PRINCIPAL_NAME_ATTRIBUTE)
.setExtractor(PrincipalNameExtractor.class.getName());
}

private MapIndexConfig springSessionIndexConfig() {
return new MapIndexConfig(HazelcastIndexedSessionRepository.PRINCIPAL_NAME_ATTRIBUTE, false);
}
}

and

@SpringBootApplication
public class NowohazelcastappApplication {

public static void main(String[] args) {
SpringApplication.run(NowohazelcastappApplication.class, args);
}
}

thats all server classes for now

and dependencies

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.4.4</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
......
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.hazelcast</groupId>
<artifactId>hazelcast</artifactId>
<version>3.12.11</version>
</dependency>
<dependency>
<groupId>org.springframework.session</groupId>
<artifactId>spring-session-hazelcast</artifactId>
</dependency>
</dependencies>

And client side configs:

@Bean
public ClientConfig clientConfig() {
ClientConfig clientConfig = new ClientConfig();
SerializerConfig serializerConfig = new SerializerConfig();
serializerConfig.setImplementation(new HazelcastSessionSerializer()).setTypeClass(MapSession.class);
clientConfig.getSerializationConfig().addSerializerConfig(serializerConfig);
return clientConfig;
}

@Bean()
public HazelcastInstance hazelcastInstance(ClientConfig clientConfig){
return HazelcastClient.newHazelcastClient(clientConfig);
}


And I`m getting this error during attemption to store session
...HazelcastSerializationException: java.lang.ClassNotFoundException: com.test.session.CustomerInSession

this is a class from the client side and i have some others classes also with such exception

Does hazelcast have any way to serialize and deserialize my CustomerInSession class (and others) without copying this class on server side ?

Валентин Твардовский

unread,
Apr 7, 2021, 8:06:43 AM4/7/21
to Hazelcast
So the main problem that server side is trying to deserialize session map info - how can I avoid this problem? Maybe I missed something in my configs?

среда, 7 апреля 2021 г. в 15:00:59 UTC+3, Валентин Твардовский:

Rafal Leszko

unread,
Apr 7, 2021, 8:34:51 AM4/7/21
to haze...@googlegroups.com
Hi,

You can check the related Hazelcast Guide: https://guides.hazelcast.org/spring-session-hazelcast/

Cheers,
Rafał

--
You received this message because you are subscribed to the Google Groups "Hazelcast" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hazelcast+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/hazelcast/3951fdb5-ea96-491c-97df-ddddb0b3b808n%40googlegroups.com.


--

Rafał Leszko
Software Engineer
   hazelcast®
 
 


This message contains confidential information and is intended only for the individuals named. If you are not the named addressee you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately by e-mail if you have received this e-mail by mistake and delete this e-mail from your system. E-mail transmission cannot be guaranteed to be secure or error-free as information could be intercepted, corrupted, lost, destroyed, arrive late or incomplete, or contain viruses. The sender therefore does not accept liability for any errors or omissions in the contents of this message, which arise as a result of e-mail transmission. If verification is required, please request a hard-copy version. -Hazelcast

Валентин Твардовский

unread,
Apr 7, 2021, 9:56:30 AM4/7/21
to haze...@googlegroups.com
Thanks a lot!

ср, 7 апр. 2021 г. в 15:34, Rafal Leszko <ra...@hazelcast.com>:
Reply all
Reply to author
Forward
0 new messages