forked from apolloconfig/apollo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add more ConfigurationProperties sample
- Loading branch information
Showing
1 changed file
with
33 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,9 @@ | ||
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 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([email protected]) | ||
*/ | ||
@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 void setCommandTimeout(int commandTimeout) { | |
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); | ||
} | ||
} |