Merge branch '2.6.x' into 2.7.x

Closes gh-32247
This commit is contained in:
Stephane Nicoll 2022-09-07 09:33:17 +02:00
commit 2fb257ad22
10 changed files with 85 additions and 11 deletions

View File

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -39,7 +39,8 @@ class HazelcastClientConfigAvailableCondition extends HazelcastConfigResourceCon
HazelcastClientConfigAvailableCondition() { HazelcastClientConfigAvailableCondition() {
super(HazelcastClientConfiguration.CONFIG_SYSTEM_PROPERTY, "file:./hazelcast-client.xml", super(HazelcastClientConfiguration.CONFIG_SYSTEM_PROPERTY, "file:./hazelcast-client.xml",
"classpath:/hazelcast-client.xml", "file:./hazelcast-client.yaml", "classpath:/hazelcast-client.yaml"); "classpath:/hazelcast-client.xml", "file:./hazelcast-client.yaml", "classpath:/hazelcast-client.yaml",
"file:./hazelcast-client.yml", "classpath:/hazelcast-client.yml");
} }
@Override @Override

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2021 the original author or authors. * Copyright 2012-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -72,7 +72,7 @@ class HazelcastClientConfiguration {
private ClientConfig loadClientConfig(Resource configLocation) throws IOException { private ClientConfig loadClientConfig(Resource configLocation) throws IOException {
URL configUrl = configLocation.getURL(); URL configUrl = configLocation.getURL();
String configFileName = configUrl.getPath(); String configFileName = configUrl.getPath();
if (configFileName.endsWith(".yaml")) { if (configFileName.endsWith(".yaml") || configFileName.endsWith(".yml")) {
return new YamlClientConfigBuilder(configUrl).build(); return new YamlClientConfigBuilder(configUrl).build();
} }
return new XmlClientConfigBuilder(configUrl).build(); return new XmlClientConfigBuilder(configUrl).build();

View File

@ -90,7 +90,7 @@ class HazelcastServerConfiguration {
private static Config loadConfig(URL configUrl) throws IOException { private static Config loadConfig(URL configUrl) throws IOException {
String configFileName = configUrl.getPath(); String configFileName = configUrl.getPath();
if (configFileName.endsWith(".yaml")) { if (configFileName.endsWith(".yaml") || configFileName.endsWith(".yml")) {
return new YamlConfigBuilder(configUrl).build(); return new YamlConfigBuilder(configUrl).build();
} }
return new XmlConfigBuilder(configUrl).build(); return new XmlConfigBuilder(configUrl).build();
@ -149,7 +149,7 @@ class HazelcastServerConfiguration {
ConfigAvailableCondition() { ConfigAvailableCondition() {
super(CONFIG_SYSTEM_PROPERTY, "file:./hazelcast.xml", "classpath:/hazelcast.xml", "file:./hazelcast.yaml", super(CONFIG_SYSTEM_PROPERTY, "file:./hazelcast.xml", "classpath:/hazelcast.xml", "file:./hazelcast.yaml",
"classpath:/hazelcast.yaml"); "classpath:/hazelcast.yaml", "file:./hazelcast.yml", "classpath:/hazelcast.yml");
} }
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2021 the original author or authors. * Copyright 2012-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -81,6 +81,14 @@ class HazelcastAutoConfigurationClientTests {
.run(assertSpecificHazelcastClient("explicit-yaml")); .run(assertSpecificHazelcastClient("explicit-yaml"));
} }
@Test
void systemPropertyWithYml() {
this.contextRunner
.withSystemProperties(HazelcastClientConfiguration.CONFIG_SYSTEM_PROPERTY
+ "=classpath:org/springframework/boot/autoconfigure/hazelcast/hazelcast-client-specific.yml")
.run(assertSpecificHazelcastClient("explicit-yml"));
}
@Test @Test
void explicitConfigFileWithXml() { void explicitConfigFileWithXml() {
this.contextRunner.withPropertyValues("spring.hazelcast.config=org/springframework/boot/autoconfigure/" this.contextRunner.withPropertyValues("spring.hazelcast.config=org/springframework/boot/autoconfigure/"
@ -95,6 +103,12 @@ class HazelcastAutoConfigurationClientTests {
.run(assertSpecificHazelcastClient("explicit-yaml")); .run(assertSpecificHazelcastClient("explicit-yaml"));
} }
@Test
void explicitConfigFileWithYml() {
this.contextRunner.withPropertyValues("spring.hazelcast.config=org/springframework/boot/autoconfigure/"
+ "hazelcast/hazelcast-client-specific.yml").run(assertSpecificHazelcastClient("explicit-yml"));
}
@Test @Test
void explicitConfigUrlWithXml() { void explicitConfigUrlWithXml() {
this.contextRunner this.contextRunner
@ -111,6 +125,14 @@ class HazelcastAutoConfigurationClientTests {
.run(assertSpecificHazelcastClient("explicit-yaml")); .run(assertSpecificHazelcastClient("explicit-yaml"));
} }
@Test
void explicitConfigUrlWithYml() {
this.contextRunner
.withPropertyValues("spring.hazelcast.config=classpath:org/springframework/"
+ "boot/autoconfigure/hazelcast/hazelcast-client-specific.yml")
.run(assertSpecificHazelcastClient("explicit-yml"));
}
@Test @Test
void unknownConfigFile() { void unknownConfigFile() {
this.contextRunner.withPropertyValues("spring.hazelcast.config=foo/bar/unknown.xml") this.contextRunner.withPropertyValues("spring.hazelcast.config=foo/bar/unknown.xml")

View File

@ -87,6 +87,17 @@ class HazelcastAutoConfigurationServerTests {
}); });
} }
@Test
void systemPropertyWithYml() {
this.contextRunner
.withSystemProperties(HazelcastServerConfiguration.CONFIG_SYSTEM_PROPERTY
+ "=classpath:org/springframework/boot/autoconfigure/hazelcast/hazelcast-specific.yml")
.run((context) -> {
Config config = context.getBean(HazelcastInstance.class).getConfig();
assertThat(config.getMapConfigs().keySet()).containsOnly("foobar");
});
}
@Test @Test
void explicitConfigFileWithXml() { void explicitConfigFileWithXml() {
this.contextRunner this.contextRunner
@ -105,6 +116,15 @@ class HazelcastAutoConfigurationServerTests {
"org/springframework/boot/autoconfigure/hazelcast/hazelcast-specific.yaml")); "org/springframework/boot/autoconfigure/hazelcast/hazelcast-specific.yaml"));
} }
@Test
void explicitConfigFileWithYml() {
this.contextRunner
.withPropertyValues("spring.hazelcast.config=org/springframework/boot/autoconfigure/hazelcast/"
+ "hazelcast-specific.yml")
.run(assertSpecificHazelcastServer(
"org/springframework/boot/autoconfigure/hazelcast/hazelcast-specific.yml"));
}
@Test @Test
void explicitConfigUrlWithXml() { void explicitConfigUrlWithXml() {
this.contextRunner this.contextRunner
@ -123,6 +143,15 @@ class HazelcastAutoConfigurationServerTests {
"org/springframework/boot/autoconfigure/hazelcast/hazelcast-specific.yaml")); "org/springframework/boot/autoconfigure/hazelcast/hazelcast-specific.yaml"));
} }
@Test
void explicitConfigUrlWithYml() {
this.contextRunner
.withPropertyValues("spring.hazelcast.config=classpath:org/springframework/"
+ "boot/autoconfigure/hazelcast/hazelcast-specific.yml")
.run(assertSpecificHazelcastServer(
"org/springframework/boot/autoconfigure/hazelcast/hazelcast-specific.yml"));
}
private ContextConsumer<AssertableApplicationContext> assertSpecificHazelcastServer(String location) { private ContextConsumer<AssertableApplicationContext> assertSpecificHazelcastServer(String location) {
return (context) -> { return (context) -> {
Config config = context.getBean(HazelcastInstance.class).getConfig(); Config config = context.getBean(HazelcastInstance.class).getConfig();

View File

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -45,7 +45,7 @@ class HazelcastAutoConfigurationTests {
void defaultConfigFile() { void defaultConfigFile() {
// no hazelcast-client.xml and hazelcast.xml is present in root classpath // no hazelcast-client.xml and hazelcast.xml is present in root classpath
// this also asserts that XML has priority over YAML // this also asserts that XML has priority over YAML
// as both hazelcast.yaml and hazelcast.xml in test classpath. // as hazelcast.yaml, hazelcast.yml, and hazelcast.xml are available.
this.contextRunner.run((context) -> { this.contextRunner.run((context) -> {
Config config = context.getBean(HazelcastInstance.class).getConfig(); Config config = context.getBean(HazelcastInstance.class).getConfig();
assertThat(config.getConfigurationUrl()).isEqualTo(new ClassPathResource("hazelcast.xml").getURL()); assertThat(config.getConfigurationUrl()).isEqualTo(new ClassPathResource("hazelcast.xml").getURL());

View File

@ -0,0 +1,7 @@
hazelcast:
network:
join:
auto-detection:
enabled: false
multicast:
enabled: false

View File

@ -0,0 +1,12 @@
hazelcast:
network:
join:
auto-detection:
enabled: false
multicast:
enabled: false
map:
foobar:
time-to-live-seconds: 3600
max-idle-seconds: 600

View File

@ -8,7 +8,7 @@ Spring Boot first attempts to create a client by checking the following configur
* A configuration file defined by the configprop:spring.hazelcast.config[] property. * A configuration file defined by the configprop:spring.hazelcast.config[] property.
* The presence of the `hazelcast.client.config` system property. * The presence of the `hazelcast.client.config` system property.
* A `hazelcast-client.xml` in the working directory or at the root of the classpath. * A `hazelcast-client.xml` in the working directory or at the root of the classpath.
* A `hazelcast-client.yaml` in the working directory or at the root of the classpath. * A `hazelcast-client.yaml` (or `hazelcast-client.yml`) in the working directory or at the root of the classpath.
WARNING: Hazelcast 3 support is deprecated. WARNING: Hazelcast 3 support is deprecated.
If you still need to downgrade to Hazelcast 3, `hazelcast-client` should be added to the classpath to configure a client. If you still need to downgrade to Hazelcast 3, `hazelcast-client` should be added to the classpath to configure a client.
@ -26,7 +26,7 @@ You could also specify the Hazelcast configuration file to use through configura
config: "classpath:config/my-hazelcast.xml" config: "classpath:config/my-hazelcast.xml"
---- ----
Otherwise, Spring Boot tries to find the Hazelcast configuration from the default locations: `hazelcast.xml` in the working directory or at the root of the classpath, or a `.yaml` counterpart in the same locations. Otherwise, Spring Boot tries to find the Hazelcast configuration from the default locations: `hazelcast.xml` in the working directory or at the root of the classpath, or a `.yaml`/`.yml` counterpart in the same locations.
We also check if the `hazelcast.config` system property is set. We also check if the `hazelcast.config` system property is set.
See the https://docs.hazelcast.org/docs/latest/manual/html-single/[Hazelcast documentation] for more details. See the https://docs.hazelcast.org/docs/latest/manual/html-single/[Hazelcast documentation] for more details.