Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
704da175
Commit
704da175
authored
Apr 29, 2019
by
Stephane Nicoll
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Polish "Add support for Hazelcast YAML configuration"
Closes gh-16632
parent
82e18ae8
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
94 additions
and
75 deletions
+94
-75
HazelcastClientFactory.java
.../boot/autoconfigure/hazelcast/HazelcastClientFactory.java
+4
-7
HazelcastInstanceFactory.java
...oot/autoconfigure/hazelcast/HazelcastInstanceFactory.java
+5
-5
HazelcastAutoConfigurationClientTests.java
...gure/hazelcast/HazelcastAutoConfigurationClientTests.java
+35
-31
HazelcastAutoConfigurationServerTests.java
...gure/hazelcast/HazelcastAutoConfigurationServerTests.java
+41
-25
HazelcastAutoConfigurationTests.java
...oconfigure/hazelcast/HazelcastAutoConfigurationTests.java
+1
-1
hazelcast-client-specific.xml
...oot/autoconfigure/hazelcast/hazelcast-client-specific.xml
+1
-1
hazelcast-client-specific.yaml
...ot/autoconfigure/hazelcast/hazelcast-client-specific.yaml
+1
-1
spring-boot-features.adoc
...ing-boot-docs/src/main/asciidoc/spring-boot-features.adoc
+6
-4
No files found.
spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/hazelcast/HazelcastClientFactory.java
View file @
704da175
/*
/*
* Copyright 2012-201
7
the original author or authors.
* Copyright 2012-201
9
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.
...
@@ -60,14 +60,11 @@ public class HazelcastClientFactory {
...
@@ -60,14 +60,11 @@ public class HazelcastClientFactory {
private
ClientConfig
getClientConfig
(
Resource
clientConfigLocation
)
private
ClientConfig
getClientConfig
(
Resource
clientConfigLocation
)
throws
IOException
{
throws
IOException
{
URL
configUrl
=
clientConfigLocation
.
getURL
();
URL
configUrl
=
clientConfigLocation
.
getURL
();
String
configFileName
=
configUrl
.
getFile
();
String
configFileName
=
configUrl
.
getPath
();
if
(
configFileName
.
endsWith
(
".yaml"
))
{
if
(
configFileName
.
endsWith
(
".xml"
))
{
return
new
XmlClientConfigBuilder
(
configUrl
).
build
();
}
else
{
return
new
YamlClientConfigBuilder
(
configUrl
).
build
();
return
new
YamlClientConfigBuilder
(
configUrl
).
build
();
}
}
return
new
XmlClientConfigBuilder
(
configUrl
).
build
();
}
}
/**
/**
...
...
spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/hazelcast/HazelcastInstanceFactory.java
View file @
704da175
/*
/*
* Copyright 2012-201
7
the original author or authors.
* Copyright 2012-201
9
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.
...
@@ -73,11 +73,11 @@ public class HazelcastInstanceFactory {
...
@@ -73,11 +73,11 @@ public class HazelcastInstanceFactory {
}
}
private
static
Config
createConfig
(
URL
configUrl
)
throws
IOException
{
private
static
Config
createConfig
(
URL
configUrl
)
throws
IOException
{
String
configFileName
=
configUrl
.
get
File
();
String
configFileName
=
configUrl
.
get
Path
();
if
(
configFileName
.
endsWith
(
".
x
ml"
))
{
if
(
configFileName
.
endsWith
(
".
ya
ml"
))
{
return
new
X
mlConfigBuilder
(
configUrl
).
build
();
return
new
Ya
mlConfigBuilder
(
configUrl
).
build
();
}
}
return
new
Ya
mlConfigBuilder
(
configUrl
).
build
();
return
new
X
mlConfigBuilder
(
configUrl
).
build
();
}
}
/**
/**
...
...
spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/hazelcast/HazelcastAutoConfigurationClientTests.java
View file @
704da175
...
@@ -30,6 +30,7 @@ import org.springframework.beans.factory.BeanCreationException;
...
@@ -30,6 +30,7 @@ import org.springframework.beans.factory.BeanCreationException;
import
org.springframework.boot.autoconfigure.AutoConfigurations
;
import
org.springframework.boot.autoconfigure.AutoConfigurations
;
import
org.springframework.boot.test.context.assertj.AssertableApplicationContext
;
import
org.springframework.boot.test.context.assertj.AssertableApplicationContext
;
import
org.springframework.boot.test.context.runner.ApplicationContextRunner
;
import
org.springframework.boot.test.context.runner.ApplicationContextRunner
;
import
org.springframework.boot.test.context.runner.ContextConsumer
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Configuration
;
...
@@ -65,57 +66,54 @@ public class HazelcastAutoConfigurationClientTests {
...
@@ -65,57 +66,54 @@ public class HazelcastAutoConfigurationClientTests {
@Test
@Test
public
void
systemPropertyWithXml
()
{
public
void
systemPropertyWithXml
()
{
systemProperty
(
HazelcastClientConfiguration
.
CONFIG_SYSTEM_PROPERTY
this
.
contextRunner
+
"=classpath:org/springframework/boot/autoconfigure/hazelcast/"
.
withSystemProperties
(
HazelcastClientConfiguration
.
CONFIG_SYSTEM_PROPERTY
+
"hazelcast-client-specific.xml"
);
+
"=classpath:org/springframework/boot/autoconfigure/hazelcast/"
+
"hazelcast-client-specific.xml"
)
.
run
(
assertSpecificHazelcastClient
(
"explicit-xml"
));
}
}
@Test
@Test
public
void
systemPropertyWithYaml
()
{
public
void
systemPropertyWithYaml
()
{
systemProperty
(
HazelcastClientConfiguration
.
CONFIG_SYSTEM_PROPERTY
this
.
contextRunner
+
"=classpath:org/springframework/boot/autoconfigure/hazelcast/"
.
withSystemProperties
(
HazelcastClientConfiguration
.
CONFIG_SYSTEM_PROPERTY
+
"hazelcast-client-specific.yaml"
);
+
"=classpath:org/springframework/boot/autoconfigure/hazelcast/"
}
+
"hazelcast-client-specific.yaml"
)
.
run
(
assertSpecificHazelcastClient
(
"explicit-yaml"
));
private
void
systemProperty
(
String
systemProperty
)
{
this
.
contextRunner
.
withSystemProperties
(
systemProperty
)
.
run
((
context
)
->
assertHazelcastClientSpecific
(
context
));
}
}
@Test
@Test
public
void
explicitConfigFileWithXml
()
{
public
void
explicitConfigFileWithXml
()
{
propertyValues
(
"spring.hazelcast.config=org/springframework/boot/autoconfigure/"
this
.
contextRunner
+
"hazelcast/hazelcast-client-specific.xml"
);
.
withPropertyValues
(
"spring.hazelcast.config=org/springframework/boot/autoconfigure/"
+
"hazelcast/hazelcast-client-specific.xml"
)
.
run
(
assertSpecificHazelcastClient
(
"explicit-xml"
));
}
}
@Test
@Test
public
void
explicitConfigFileWithYaml
()
{
public
void
explicitConfigFileWithYaml
()
{
propertyValues
(
"spring.hazelcast.config=org/springframework/boot/autoconfigure/"
this
.
contextRunner
+
"hazelcast/hazelcast-client-specific.yaml"
);
.
withPropertyValues
(
"spring.hazelcast.config=org/springframework/boot/autoconfigure/"
+
"hazelcast/hazelcast-client-specific.yaml"
)
.
run
(
assertSpecificHazelcastClient
(
"explicit-yaml"
));
}
}
@Test
@Test
public
void
explicitConfigUrlWithXml
()
{
public
void
explicitConfigUrlWithXml
()
{
propertyValues
(
"spring.hazelcast.config=classpath:org/springframework/"
this
.
contextRunner
.
withPropertyValues
(
+
"boot/autoconfigure/hazelcast/hazelcast-client-specific.xml"
);
"spring.hazelcast.config=classpath:org/springframework/"
+
"boot/autoconfigure/hazelcast/hazelcast-client-specific.xml"
)
.
run
(
assertSpecificHazelcastClient
(
"explicit-xml"
));
}
}
@Test
@Test
public
void
explicitConfigUrlWithYaml
()
{
public
void
explicitConfigUrlWithYaml
()
{
propertyValues
(
"spring.hazelcast.config=classpath:org/springframework/"
this
.
contextRunner
.
withPropertyValues
(
+
"boot/autoconfigure/hazelcast/hazelcast-client-specific.yaml"
);
"spring.hazelcast.config=classpath:org/springframework/"
}
+
"boot/autoconfigure/hazelcast/hazelcast-client-specific.yaml"
)
.
run
(
assertSpecificHazelcastClient
(
"explicit-yaml"
));
private
void
propertyValues
(
String
propertyValues
)
{
this
.
contextRunner
.
withPropertyValues
(
propertyValues
)
.
run
((
context
)
->
assertHazelcastClientSpecific
(
context
));
}
private
static
void
assertHazelcastClientSpecific
(
AssertableApplicationContext
context
)
{
assertThat
(
context
).
getBean
(
HazelcastInstance
.
class
)
.
isInstanceOf
(
HazelcastInstance
.
class
)
.
has
(
labelEqualTo
(
"configured-client"
));
}
}
@Test
@Test
...
@@ -135,6 +133,12 @@ public class HazelcastAutoConfigurationClientTests {
...
@@ -135,6 +133,12 @@ public class HazelcastAutoConfigurationClientTests {
.
isInstanceOf
(
HazelcastClientProxy
.
class
));
.
isInstanceOf
(
HazelcastClientProxy
.
class
));
}
}
private
ContextConsumer
<
AssertableApplicationContext
>
assertSpecificHazelcastClient
(
String
label
)
{
return
(
context
)
->
assertThat
(
context
).
getBean
(
HazelcastInstance
.
class
)
.
isInstanceOf
(
HazelcastInstance
.
class
).
has
(
labelEqualTo
(
label
));
}
private
static
Condition
<
HazelcastInstance
>
labelEqualTo
(
String
label
)
{
private
static
Condition
<
HazelcastInstance
>
labelEqualTo
(
String
label
)
{
return
new
Condition
<>((
o
)
->
((
HazelcastClientProxy
)
o
).
getClientConfig
()
return
new
Condition
<>((
o
)
->
((
HazelcastClientProxy
)
o
).
getClientConfig
()
.
getLabels
().
stream
().
anyMatch
((
e
)
->
e
.
equals
(
label
)),
.
getLabels
().
stream
().
anyMatch
((
e
)
->
e
.
equals
(
label
)),
...
...
spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/hazelcast/HazelcastAutoConfigurationServerTests.java
View file @
704da175
...
@@ -29,6 +29,7 @@ import org.springframework.beans.factory.BeanCreationException;
...
@@ -29,6 +29,7 @@ import org.springframework.beans.factory.BeanCreationException;
import
org.springframework.boot.autoconfigure.AutoConfigurations
;
import
org.springframework.boot.autoconfigure.AutoConfigurations
;
import
org.springframework.boot.test.context.assertj.AssertableApplicationContext
;
import
org.springframework.boot.test.context.assertj.AssertableApplicationContext
;
import
org.springframework.boot.test.context.runner.ApplicationContextRunner
;
import
org.springframework.boot.test.context.runner.ApplicationContextRunner
;
import
org.springframework.boot.test.context.runner.ContextConsumer
;
import
org.springframework.boot.testsupport.runner.classpath.ClassPathExclusions
;
import
org.springframework.boot.testsupport.runner.classpath.ClassPathExclusions
;
import
org.springframework.boot.testsupport.runner.classpath.ModifiedClassPathRunner
;
import
org.springframework.boot.testsupport.runner.classpath.ModifiedClassPathRunner
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Bean
;
...
@@ -61,55 +62,70 @@ public class HazelcastAutoConfigurationServerTests {
...
@@ -61,55 +62,70 @@ public class HazelcastAutoConfigurationServerTests {
@Test
@Test
public
void
systemPropertyWithXml
()
{
public
void
systemPropertyWithXml
()
{
systemProperty
(
HazelcastServerConfiguration
.
CONFIG_SYSTEM_PROPERTY
this
.
contextRunner
+
"=classpath:org/springframework/boot/autoconfigure/hazelcast/hazelcast-specific.xml"
);
.
withSystemProperties
(
HazelcastServerConfiguration
.
CONFIG_SYSTEM_PROPERTY
+
"=classpath:org/springframework/boot/autoconfigure/hazelcast/hazelcast-specific.xml"
)
.
run
((
context
)
->
{
Config
config
=
context
.
getBean
(
HazelcastInstance
.
class
).
getConfig
();
assertThat
(
config
.
getMapConfigs
().
keySet
()).
containsOnly
(
"foobar"
);
});
}
}
@Test
@Test
public
void
systemPropertyWithYaml
()
{
public
void
systemPropertyWithYaml
()
{
systemProperty
(
HazelcastServerConfiguration
.
CONFIG_SYSTEM_PROPERTY
this
.
contextRunner
+
"=classpath:org/springframework/boot/autoconfigure/hazelcast/hazelcast-specific.yaml"
);
.
withSystemProperties
(
HazelcastServerConfiguration
.
CONFIG_SYSTEM_PROPERTY
}
+
"=classpath:org/springframework/boot/autoconfigure/hazelcast/hazelcast-specific.yaml"
)
.
run
((
context
)
->
{
private
void
systemProperty
(
String
systemProperties
)
{
Config
config
=
context
.
getBean
(
HazelcastInstance
.
class
).
getConfig
();
this
.
contextRunner
.
withSystemProperties
(
systemProperties
)
assertThat
(
config
.
getMapConfigs
().
keySet
()).
containsOnly
(
"foobar"
);
.
run
((
context
)
->
assertHazelcastSpecific
(
context
)
);
}
);
}
}
@Test
@Test
public
void
explicitConfigFileWithXml
()
{
public
void
explicitConfigFileWithXml
()
{
p
ropertyValues
(
this
.
contextRunner
.
withP
ropertyValues
(
"spring.hazelcast.config=org/springframework/boot/autoconfigure/hazelcast/"
"spring.hazelcast.config=org/springframework/boot/autoconfigure/hazelcast/"
+
"hazelcast-specific.xml"
);
+
"hazelcast-specific.xml"
)
.
run
(
assertSpecificHazelcastServer
(
"org/springframework/boot/autoconfigure/hazelcast/hazelcast-specific.xml"
));
}
}
@Test
@Test
public
void
explicitConfigFileWithYaml
()
{
public
void
explicitConfigFileWithYaml
()
{
p
ropertyValues
(
this
.
contextRunner
.
withP
ropertyValues
(
"spring.hazelcast.config=org/springframework/boot/autoconfigure/hazelcast/"
"spring.hazelcast.config=org/springframework/boot/autoconfigure/hazelcast/"
+
"hazelcast-specific.yaml"
);
+
"hazelcast-specific.yaml"
)
.
run
(
assertSpecificHazelcastServer
(
"org/springframework/boot/autoconfigure/hazelcast/hazelcast-specific.yaml"
));
}
}
@Test
@Test
public
void
explicitConfigUrlWithXml
()
{
public
void
explicitConfigUrlWithXml
()
{
propertyValues
(
"spring.hazelcast.config=classpath:org/springframework/"
this
.
contextRunner
+
"boot/autoconfigure/hazelcast/hazelcast-specific.xml"
);
.
withPropertyValues
(
"spring.hazelcast.config=classpath:org/springframework/"
+
"boot/autoconfigure/hazelcast/hazelcast-specific.xml"
)
.
run
(
assertSpecificHazelcastServer
(
"org/springframework/boot/autoconfigure/hazelcast/hazelcast-specific.xml"
));
}
}
@Test
@Test
public
void
explicitConfigUrlWithYaml
()
{
public
void
explicitConfigUrlWithYaml
()
{
propertyValues
(
"spring.hazelcast.config=classpath:org/springframework/"
this
.
contextRunner
+
"boot/autoconfigure/hazelcast/hazelcast-specific.yaml"
);
.
withPropertyValues
(
}
"spring.hazelcast.config=classpath:org/springframework/"
+
"boot/autoconfigure/hazelcast/hazelcast-specific.yaml"
)
private
void
propertyValues
(
String
propertyValues
)
{
.
run
(
assertSpecificHazelcastServer
(
this
.
contextRunner
.
withPropertyValues
(
propertyValues
)
"org/springframework/boot/autoconfigure/hazelcast/hazelcast-specific.yaml"
));
.
run
((
context
)
->
assertHazelcastSpecific
(
context
));
}
}
private
static
void
assertHazelcastSpecific
(
AssertableApplicationContext
context
)
{
private
ContextConsumer
<
AssertableApplicationContext
>
assertSpecificHazelcastServer
(
Config
config
=
context
.
getBean
(
HazelcastInstance
.
class
).
getConfig
();
String
location
)
{
assertThat
(
config
.
getMapConfigs
().
keySet
()).
containsOnly
(
"foobar"
);
return
(
context
)
->
{
Config
config
=
context
.
getBean
(
HazelcastInstance
.
class
).
getConfig
();
assertThat
(
config
.
getConfigurationUrl
()).
asString
().
endsWith
(
location
);
};
}
}
@Test
@Test
...
...
spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/hazelcast/HazelcastAutoConfigurationTests.java
View file @
704da175
/*
/*
* Copyright 2012-201
8
the original author or authors.
* Copyright 2012-201
9
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.
...
...
spring-boot-project/spring-boot-autoconfigure/src/test/resources/org/springframework/boot/autoconfigure/hazelcast/hazelcast-client-specific.xml
View file @
704da175
...
@@ -3,7 +3,7 @@
...
@@ -3,7 +3,7 @@
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://www.hazelcast.com/schema/client-config hazelcast-client-config-3.12.xsd"
>
xsi:schemaLocation=
"http://www.hazelcast.com/schema/client-config hazelcast-client-config-3.12.xsd"
>
<client-labels>
<client-labels>
<label>
configured-client
</label>
<label>
explicit-xml
</label>
</client-labels>
</client-labels>
</hazelcast-client>
</hazelcast-client>
spring-boot-project/spring-boot-autoconfigure/src/test/resources/org/springframework/boot/autoconfigure/hazelcast/hazelcast-client-specific.yaml
View file @
704da175
hazelcast-client
:
hazelcast-client
:
client-labels
:
client-labels
:
-
configured-client
-
explicit-yaml
spring-boot-project/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc
View file @
704da175
...
@@ -6539,8 +6539,8 @@ If you define a `com.hazelcast.config.Config` bean, Spring Boot uses that. If yo
...
@@ -6539,8 +6539,8 @@ If you define a `com.hazelcast.config.Config` bean, Spring Boot uses that. If yo
configuration defines an instance name, Spring Boot tries to locate an existing instance
configuration defines an instance name, Spring Boot tries to locate an existing instance
rather than creating a new one.
rather than creating a new one.
You could also specify the
`hazelcast.xml` configuration file to use through
You could also specify the
Hazelcast configuration file to use through configuration, as
configuration, as
shown in the following example:
shown in the following example:
[source,properties,indent=0]
[source,properties,indent=0]
----
----
...
@@ -6548,8 +6548,9 @@ configuration, as shown in the following example:
...
@@ -6548,8 +6548,9 @@ configuration, as shown in the following example:
----
----
Otherwise, Spring Boot tries to find the Hazelcast configuration from the default
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. We
locations: `hazelcast.xml` in the working directory or at the root of the classpath, or
also check if the `hazelcast.config` system property is set. See the
a `.yaml` counterpart in the same locations. 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
https://docs.hazelcast.org/docs/latest/manual/html-single/[Hazelcast documentation] for
more details.
more details.
...
@@ -6560,6 +6561,7 @@ client by checking the following configuration options:
...
@@ -6560,6 +6561,7 @@ client by checking the following configuration options:
* A configuration file defined by the `spring.hazelcast.config` property.
* A configuration file defined by the `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.
NOTE: Spring Boot also has
NOTE: Spring Boot also has
<<boot-features-caching-provider-hazelcast,explicit caching support for Hazelcast>>. If
<<boot-features-caching-provider-hazelcast,explicit caching support for Hazelcast>>. If
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment