Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
apollo
Project
Overview
Details
Activity
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
openSource
apollo
Commits
6d2d4596
Commit
6d2d4596
authored
Oct 09, 2017
by
nobodyiam
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add more ConfigurationProperties sample
parent
395dcb87
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
33 additions
and
4 deletions
+33
-4
SampleRedisConfig.java
.../demo/spring/springBootDemo/config/SampleRedisConfig.java
+33
-4
No files found.
apollo-demo/src/main/java/com/ctrip/framework/apollo/demo/spring/springBootDemo/config/SampleRedisConfig.java
View file @
6d2d4596
package
com
.
ctrip
.
framework
.
apollo
.
demo
.
spring
.
springBootDemo
.
config
;
import
com.google.common.collect.Lists
;
import
com.google.common.collect.Maps
;
import
java.util.List
;
import
java.util.Map
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.boot.context.properties.ConfigurationProperties
;
...
...
@@ -9,22 +13,38 @@ import org.springframework.stereotype.Component;
import
javax.annotation.PostConstruct
;
/**
* You may set up data like the following in Apollo:
* <pre>
* redis.cache.expireSeconds = 100
* redis.cache.clusterNodes = 1,2
* redis.cache.commandTimeout = 50
* redis.cache.someMap.key1 = a
* redis.cache.someMap.key2 = b
* redis.cache.someList[0] = c
* redis.cache.someList[1] = d
* </pre>
*
* @author Jason Song(song_s@ctrip.com)
*/
@ConfigurationProperties
(
prefix
=
"redis.cache"
)
@Component
(
"sampleRedisConfig"
)
@RefreshScope
public
class
SampleRedisConfig
{
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
SampleRedisConfig
.
class
);
private
int
expireSeconds
;
private
String
clusterNodes
;
private
int
commandTimeout
;
private
Map
<
String
,
String
>
someMap
=
Maps
.
newLinkedHashMap
();
private
List
<
String
>
someList
=
Lists
.
newLinkedList
();
@PostConstruct
private
void
initialize
()
{
logger
.
info
(
"SampleRedisConfig initialized - expireSeconds: {}, clusterNodes: {}, commandTimeout: {}"
,
expireSeconds
,
clusterNodes
,
commandTimeout
);
logger
.
info
(
"SampleRedisConfig initialized - expireSeconds: {}, clusterNodes: {}, commandTimeout: {}, someMap: {}, someList: {}"
,
expireSeconds
,
clusterNodes
,
commandTimeout
,
someMap
,
someList
);
}
public
void
setExpireSeconds
(
int
expireSeconds
)
{
...
...
@@ -39,9 +59,18 @@ public class SampleRedisConfig {
this
.
commandTimeout
=
commandTimeout
;
}
public
Map
<
String
,
String
>
getSomeMap
()
{
return
someMap
;
}
public
List
<
String
>
getSomeList
()
{
return
someList
;
}
@Override
public
String
toString
()
{
return
String
.
format
(
"[SampleRedisConfig] expireSeconds: %d, clusterNodes: %s, commandTimeout: %d"
,
expireSeconds
,
clusterNodes
,
commandTimeout
);
return
String
.
format
(
"[SampleRedisConfig] expireSeconds: %d, clusterNodes: %s, commandTimeout: %d, someMap: %s, someList: %s"
,
expireSeconds
,
clusterNodes
,
commandTimeout
,
someMap
,
someList
);
}
}
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