From 578855f512ec561814bb09a51ac9e6fa2a6a884e Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Tue, 4 Jan 2022 10:39:20 +0100 Subject: [PATCH] Restore support for Hazelcast 3 See gh-28801 --- .../hazelcast/HazelcastServerConfiguration.java | 6 +++++- .../Hazelcast3AutoConfigurationTests.java | 14 ++++++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/hazelcast/HazelcastServerConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/hazelcast/HazelcastServerConfiguration.java index b72cd2471d..acfc128ea2 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/hazelcast/HazelcastServerConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/hazelcast/HazelcastServerConfiguration.java @@ -114,7 +114,11 @@ class HazelcastServerConfiguration { @Bean @Order(0) HazelcastConfigCustomizer springManagedContextHazelcastConfigCustomizer(ApplicationContext applicationContext) { - return (config) -> config.setManagedContext(new SpringManagedContext(applicationContext)); + return (config) -> { + SpringManagedContext managementContext = new SpringManagedContext(); + managementContext.setApplicationContext(applicationContext); + config.setManagedContext(managementContext); + }; } } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/hazelcast/Hazelcast3AutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/hazelcast/Hazelcast3AutoConfigurationTests.java index 1478cb35c7..98d51cb79d 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/hazelcast/Hazelcast3AutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/hazelcast/Hazelcast3AutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,6 +20,7 @@ import com.hazelcast.client.impl.clientside.HazelcastClientProxy; import com.hazelcast.config.Config; import com.hazelcast.core.Hazelcast; import com.hazelcast.core.HazelcastInstance; +import com.hazelcast.spring.context.SpringManagedContext; import org.assertj.core.api.Condition; import org.junit.jupiter.api.Test; @@ -39,7 +40,8 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Stephane Nicoll */ @ClassPathExclusions("hazelcast*.jar") -@ClassPathOverrides({ "com.hazelcast:hazelcast:3.12.8", "com.hazelcast:hazelcast-client:3.12.8" }) +@ClassPathOverrides({ "com.hazelcast:hazelcast:3.12.8", "com.hazelcast:hazelcast-client:3.12.8", + "com.hazelcast:hazelcast-spring:3.12.8" }) class Hazelcast3AutoConfigurationTests { private final ApplicationContextRunner contextRunner = new ApplicationContextRunner() @@ -70,6 +72,14 @@ class Hazelcast3AutoConfigurationTests { } } + @Test + void autoConfiguredConfigUsesSpringManagedContext() { + this.contextRunner.run((context) -> { + Config config = context.getBean(HazelcastInstance.class).getConfig(); + assertThat(config.getManagedContext()).isInstanceOf(SpringManagedContext.class); + }); + } + private ContextConsumer assertSpecificHazelcastClient(String label) { return (context) -> assertThat(context).getBean(HazelcastInstance.class).isInstanceOf(HazelcastInstance.class) .has(labelEqualTo(label));