forked from sxfad/config-keeper
-
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.
- Loading branch information
Showing
14 changed files
with
410 additions
and
161 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,6 +1,6 @@ | ||
spring: | ||
application: | ||
name: config-demo | ||
name: config-keeper-demo | ||
|
||
profiles: | ||
active: ${profile:dev} | ||
|
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,12 +1,9 @@ | ||
package com.suixingpay.config.client; | ||
|
||
import com.suixingpay.config.client.dao.ConfigDAO; | ||
import com.suixingpay.config.client.dao.ConfigDAOImpl; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.actuate.endpoint.Endpoint; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
|
@@ -17,25 +14,12 @@ | |
* @review: qiujiayu[[email protected]]/2017年9月21日 下午3:33:11 | ||
*/ | ||
@Configuration | ||
@ConditionalOnBean(ConfigDAO.class) | ||
@ConditionalOnClass(Endpoint.class) | ||
public class SxfConfigClientAutoConfiguration { | ||
|
||
@Autowired | ||
private SxfConfigClientProperties configClientProperties; | ||
|
||
@Bean | ||
@ConditionalOnMissingBean(ConfigDAO.class) | ||
public ConfigDAO sxfConfigDAO() { | ||
return new ConfigDAOImpl(configClientProperties); | ||
} | ||
|
||
@Configuration | ||
@ConditionalOnBean(ConfigDAO.class) | ||
@ConditionalOnClass(Endpoint.class) | ||
protected static class SxfConfigVersionEndpointConfiguration { | ||
|
||
@Bean | ||
public SxfConfigLocalVersionEndpoint sxfConfigLocalVersionEndpoint(ConfigDAO configDAO) { | ||
return new SxfConfigLocalVersionEndpoint(configDAO); | ||
} | ||
public SxfConfigLocalVersionEndpoint sxfConfigLocalVersionEndpoint(ConfigDAO configDAO) { | ||
return new SxfConfigLocalVersionEndpoint(configDAO); | ||
} | ||
} |
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
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,15 +1,13 @@ | ||
package com.suixingpay.config.client; | ||
|
||
import com.suixingpay.config.client.dao.ConfigDAO; | ||
import com.suixingpay.config.common.to.PropertySource; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.cloud.bootstrap.config.PropertySourceLocator; | ||
import org.springframework.core.annotation.Order; | ||
import org.springframework.core.env.CompositePropertySource; | ||
import org.springframework.core.env.MapPropertySource; | ||
|
||
import com.suixingpay.config.client.dao.ConfigDAO; | ||
import com.suixingpay.config.common.to.PropertySource; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
|
||
/** | ||
* @author: qiujiayu[[email protected]] | ||
* @date: 2017年9月1日 下午5:08:52 | ||
|
@@ -29,7 +27,7 @@ public class SxfConfigServicePropertySourceLocator implements PropertySourceLoca | |
private SxfConfigClientProperties configClientProperties; | ||
|
||
public SxfConfigServicePropertySourceLocator(ConfigDAO configDAO, | ||
SxfConfigClientProperties configClientProperties) { | ||
SxfConfigClientProperties configClientProperties) { | ||
this.configDAO = configDAO; | ||
this.configClientProperties = configClientProperties; | ||
} | ||
|
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
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,26 +1,19 @@ | ||
package com.suixingpay.config.client.dao; | ||
|
||
import java.io.ByteArrayOutputStream; | ||
import java.io.File; | ||
import java.io.FileInputStream; | ||
import java.io.FileOutputStream; | ||
import java.io.InputStream; | ||
import java.io.OutputStream; | ||
import java.util.List; | ||
|
||
import com.suixingpay.config.client.AddApplicationInstanceInfoInterceptor; | ||
import com.suixingpay.config.client.SxfConfigClientProperties; | ||
import com.suixingpay.config.client.util.JsonUtil; | ||
import com.suixingpay.config.common.to.PropertySource; | ||
import com.suixingpay.config.common.to.VersionDTO; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.http.client.SimpleClientHttpRequestFactory; | ||
import org.springframework.http.client.support.BasicAuthorizationInterceptor; | ||
import org.springframework.web.client.RestTemplate; | ||
|
||
import com.suixingpay.config.client.SxfConfigClientProperties; | ||
import com.suixingpay.config.client.util.JsonUtil; | ||
import com.suixingpay.config.common.to.PropertySource; | ||
import com.suixingpay.config.common.to.VersionDTO; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
import java.io.*; | ||
import java.util.List; | ||
|
||
/** | ||
* @author: qiujiayu[[email protected]] | ||
|
@@ -49,9 +42,10 @@ public class ConfigDAOImpl implements ConfigDAO { | |
|
||
private String applicationConfigCacheFile; | ||
|
||
private PropertySource globalConfigCache; | ||
// refresh 后 ConfigDAOImpl 在Spring 容器中不是单例,需要使用static | ||
private static PropertySource globalConfigCache; | ||
|
||
private PropertySource applicationConfigCache; | ||
private static PropertySource applicationConfigCache; | ||
|
||
private RestTemplate restTemplate; | ||
|
||
|
@@ -198,7 +192,7 @@ public PropertySource getApplicationConfig() { | |
String json = responseEntity.getBody(); | ||
propertySource = JsonUtil.jsonToObject(json, PropertySource.class); | ||
if (null != propertySource) { | ||
this.applicationConfigCache = propertySource; | ||
applicationConfigCache = propertySource; | ||
writeFile(this.applicationConfigCacheFile, json); | ||
} | ||
} | ||
|
@@ -213,12 +207,12 @@ public PropertySource getApplicationConfig() { | |
|
||
@Override | ||
public PropertySource getApplicationConfigLocalCache() { | ||
if (null != this.applicationConfigCache) { | ||
return this.applicationConfigCache; | ||
if (null != applicationConfigCache) { | ||
return applicationConfigCache; | ||
} | ||
String json = readFile(applicationConfigCacheFile); | ||
if (null != json && !json.trim().isEmpty()) { | ||
this.applicationConfigCache = JsonUtil.jsonToObject(json, PropertySource.class); | ||
applicationConfigCache = JsonUtil.jsonToObject(json, PropertySource.class); | ||
} | ||
return applicationConfigCache; | ||
} | ||
|
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 |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
|
||
/** | ||
* 连接配置中心失败 | ||
* | ||
* | ||
* @author: qiujiayu[[email protected]] | ||
* @date: 2017年9月25日 上午11:24:48 | ||
* @version: V1.0 | ||
|
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 |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
|
||
/** | ||
* bootstrap.yml未设置spring.application.name | ||
* | ||
* | ||
* @author: qiujiayu[[email protected]] | ||
* @date: 2017年9月25日 下午1:04:12 | ||
* @version: V1.0 | ||
|
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 |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
|
||
/** | ||
* 未设置profile异常 | ||
* | ||
* | ||
* @author: qiujiayu[[email protected]] | ||
* @date: 2017年9月25日 上午11:43:18 | ||
* @version: V1.0 | ||
|
3 changes: 1 addition & 2 deletions
3
...in/java/com/suixingpay/config/client/failureanalyzer/ConfigConnectionFailureAnalyzer.java
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,10 +1,9 @@ | ||
package com.suixingpay.config.client.failureanalyzer; | ||
|
||
import com.suixingpay.config.client.exception.ConfigConnectionFailureException; | ||
import org.springframework.boot.diagnostics.AbstractFailureAnalyzer; | ||
import org.springframework.boot.diagnostics.FailureAnalysis; | ||
|
||
import com.suixingpay.config.client.exception.ConfigConnectionFailureException; | ||
|
||
/** | ||
* @author: qiujiayu[[email protected]] | ||
* @date: 2017年9月25日 上午11:26:36 | ||
|
5 changes: 2 additions & 3 deletions
5
...ava/com/suixingpay/config/client/failureanalyzer/UnSetApplicationNameFailureAnalyzer.java
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,13 +1,12 @@ | ||
package com.suixingpay.config.client.failureanalyzer; | ||
|
||
import com.suixingpay.config.client.exception.UnSetApplicationNameException; | ||
import org.springframework.boot.diagnostics.AbstractFailureAnalyzer; | ||
import org.springframework.boot.diagnostics.FailureAnalysis; | ||
|
||
import com.suixingpay.config.client.exception.UnSetApplicationNameException; | ||
|
||
/** | ||
* 未设置spring.application.name异常分析 | ||
* | ||
* | ||
* @author: qiujiayu[[email protected]] | ||
* @date: 2017年9月25日 上午11:45:32 | ||
* @version: V1.0 | ||
|
5 changes: 2 additions & 3 deletions
5
...c/main/java/com/suixingpay/config/client/failureanalyzer/UnSetProfileFailureAnalyzer.java
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,13 +1,12 @@ | ||
package com.suixingpay.config.client.failureanalyzer; | ||
|
||
import com.suixingpay.config.client.exception.UnSetProfileException; | ||
import org.springframework.boot.diagnostics.AbstractFailureAnalyzer; | ||
import org.springframework.boot.diagnostics.FailureAnalysis; | ||
|
||
import com.suixingpay.config.client.exception.UnSetProfileException; | ||
|
||
/** | ||
* 未设置profile异常分析 | ||
* | ||
* | ||
* @author: qiujiayu[[email protected]] | ||
* @date: 2017年9月25日 上午11:45:32 | ||
* @version: V1.0 | ||
|
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,17 +1,16 @@ | ||
package com.suixingpay.config.client.util; | ||
|
||
import java.io.IOException; | ||
import java.util.Map; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import com.fasterxml.jackson.core.JsonGenerationException; | ||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.core.type.TypeReference; | ||
import com.fasterxml.jackson.databind.JsonMappingException; | ||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.io.IOException; | ||
import java.util.Map; | ||
|
||
/** | ||
* @author: qiujiayu[[email protected]] | ||
|
@@ -25,7 +24,7 @@ public class JsonUtil { | |
|
||
/** | ||
* 生成JSON字符串 | ||
* | ||
* | ||
* @param obj | ||
* @return | ||
* @throws JsonProcessingException | ||
|
@@ -43,7 +42,7 @@ public static String objectToJson(Object obj) { | |
|
||
/** | ||
* 生成JSON字符串 | ||
* | ||
* | ||
* @param obj | ||
* @param serializationView | ||
* @return | ||
|
@@ -60,9 +59,9 @@ public static String objectToJson(Object obj, Class<?> serializationView) throws | |
|
||
/** | ||
* 将JSON字符串转化为 指定类型 | ||
* | ||
* | ||
* @param json json | ||
* @param c 期望类型 | ||
* @param c 期望类型 | ||
* @return T 结果 | ||
*/ | ||
public static <T> T jsonToObject(String json, Class<T> c) { | ||
|
@@ -88,9 +87,9 @@ public static <T> Map<String, T> jsonToMap(String json) { | |
|
||
/** | ||
* 将JSON字符串转化为 指定类型 | ||
* | ||
* | ||
* @param json json | ||
* @param c 期望类型 | ||
* @param c 期望类型 | ||
* @return T 结果 | ||
*/ | ||
public static <T> T jsonToObject(String json, TypeReference<T> c) { | ||
|
@@ -107,7 +106,7 @@ public static <T> T jsonToObject(String json, TypeReference<T> c) { | |
|
||
/** | ||
* 获取Json树 | ||
* | ||
* | ||
* @param json | ||
* @return | ||
*/ | ||
|
Oops, something went wrong.