Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
superrain51
apollo
提交
84053f70
apollo
项目概览
superrain51
/
apollo
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
apollo
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
84053f70
编写于
7月 25, 2017
作者:
J
Jason Song
提交者:
GitHub
7月 25, 2017
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #672 from nobodyiam/refresh-scope-demo-2
add more refresh scope sample
上级
7b41718c
d34c91fc
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
84 addition
and
5 deletion
+84
-5
apollo-demo/src/main/java/com/ctrip/framework/apollo/demo/spring/common/bean/NormalBean.java
.../framework/apollo/demo/spring/common/bean/NormalBean.java
+5
-0
apollo-demo/src/main/java/com/ctrip/framework/apollo/demo/spring/common/config/AppConfig.java
...framework/apollo/demo/spring/common/config/AppConfig.java
+3
-1
apollo-demo/src/main/java/com/ctrip/framework/apollo/demo/spring/common/refresh/ApolloRefreshConfig.java
...pollo/demo/spring/common/refresh/ApolloRefreshConfig.java
+8
-2
apollo-demo/src/main/java/com/ctrip/framework/apollo/demo/spring/javaConfigDemo/config/RefreshScopeConfig.java
...demo/spring/javaConfigDemo/config/RefreshScopeConfig.java
+3
-0
apollo-demo/src/main/java/com/ctrip/framework/apollo/demo/spring/springBootDemo/config/SampleRedisConfig.java
.../demo/spring/springBootDemo/config/SampleRedisConfig.java
+12
-1
apollo-demo/src/main/java/com/ctrip/framework/apollo/demo/spring/springBootDemo/refresh/SpringBootApolloRefreshConfig.java
...springBootDemo/refresh/SpringBootApolloRefreshConfig.java
+48
-0
apollo-demo/src/main/resources/spring.xml
apollo-demo/src/main/resources/spring.xml
+5
-1
未找到文件。
apollo-demo/src/main/java/com/ctrip/framework/apollo/demo/spring/common/bean/NormalBean.java
浏览文件 @
84053f70
...
...
@@ -25,4 +25,9 @@ public class NormalBean {
public
void
setBatch
(
int
batch
)
{
this
.
batch
=
batch
;
}
@Override
public
String
toString
()
{
return
String
.
format
(
"[NormalBean] timeout: %d, batch: %d"
,
timeout
,
batch
);
}
}
apollo-demo/src/main/java/com/ctrip/framework/apollo/demo/spring/common/config/AppConfig.java
浏览文件 @
84053f70
...
...
@@ -4,6 +4,7 @@ import com.ctrip.framework.apollo.demo.spring.common.bean.NormalBean;
import
com.ctrip.framework.apollo.spring.annotation.EnableApolloConfig
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.cloud.context.config.annotation.RefreshScope
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
...
...
@@ -13,7 +14,8 @@ import org.springframework.context.annotation.Configuration;
@Configuration
@EnableApolloConfig
(
value
=
"application"
,
order
=
10
)
public
class
AppConfig
{
@Bean
@Bean
(
"normalBean"
)
@RefreshScope
public
NormalBean
normalBean
(
@Value
(
"${batch:100}"
)
int
batch
)
{
NormalBean
bean
=
new
NormalBean
();
bean
.
setBatch
(
batch
);
...
...
apollo-demo/src/main/java/com/ctrip/framework/apollo/demo/spring/common/refresh/ApolloRefreshConfig.java
浏览文件 @
84053f70
...
...
@@ -2,6 +2,7 @@ package com.ctrip.framework.apollo.demo.spring.common.refresh;
import
com.ctrip.framework.apollo.Config
;
import
com.ctrip.framework.apollo.ConfigChangeListener
;
import
com.ctrip.framework.apollo.demo.spring.common.bean.NormalBean
;
import
com.ctrip.framework.apollo.demo.spring.common.bean.RefreshScopeBean
;
import
com.ctrip.framework.apollo.model.ConfigChangeEvent
;
import
com.ctrip.framework.apollo.spring.annotation.ApolloConfig
;
...
...
@@ -32,21 +33,26 @@ public class ApolloRefreshConfig implements ConfigChangeListener {
private
RefreshScope
refreshScope
;
@Autowired
@Qualifier
(
"refreshScopeBean"
)
private
RefreshScopeBean
refreshScopeBean
;
@Autowired
private
NormalBean
normalBean
;
@PostConstruct
private
void
init
()
{
logger
.
info
(
refreshScopeBean
.
toString
());
config
.
addChangeListener
(
this
);
anotherConfig
.
addChangeListener
(
this
);
}
@Override
public
void
onChange
(
ConfigChangeEvent
changeEvent
)
{
//could also call refreshScope.refreshAll();
logger
.
info
(
"refreshScopeBean before refresh {}"
,
refreshScopeBean
.
toString
());
//could also call refreshScope.refreshAll();
refreshScope
.
refresh
(
"refreshScopeBean"
);
logger
.
info
(
"refreshScopeBean after refresh {}"
,
refreshScopeBean
.
toString
());
logger
.
info
(
"normalBean with refresh scope before refresh {}"
,
normalBean
.
toString
());
refreshScope
.
refresh
(
"normalBean"
);
logger
.
info
(
"normalBean with refresh scope after refresh {}"
,
normalBean
.
toString
());
}
}
apollo-demo/src/main/java/com/ctrip/framework/apollo/demo/spring/javaConfigDemo/config/RefreshScopeConfig.java
浏览文件 @
84053f70
package
com.ctrip.framework.apollo.demo.spring.javaConfigDemo.config
;
import
com.ctrip.framework.apollo.demo.spring.common.refresh.ApolloRefreshConfig
;
import
org.springframework.cloud.autoconfigure.RefreshAutoConfiguration
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Import
;
...
...
apollo-demo/src/main/java/com/ctrip/framework/apollo/demo/spring/springBootDemo/config/SampleRedisConfig.java
浏览文件 @
84053f70
package
com.ctrip.framework.apollo.demo.spring.springBootDemo.config
;
import
com.ctrip.framework.apollo.ConfigChangeListener
;
import
com.ctrip.framework.apollo.model.ConfigChangeEvent
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.boot.context.properties.ConfigurationProperties
;
import
org.springframework.cloud.context.config.annotation.RefreshScope
;
import
org.springframework.stereotype.Component
;
import
javax.annotation.PostConstruct
;
...
...
@@ -11,7 +15,8 @@ import javax.annotation.PostConstruct;
* @author Jason Song(song_s@ctrip.com)
*/
@ConfigurationProperties
(
prefix
=
"redis.cache"
)
@Component
@Component
(
"sampleRedisConfig"
)
@RefreshScope
public
class
SampleRedisConfig
{
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
SampleRedisConfig
.
class
);
...
...
@@ -36,4 +41,10 @@ public class SampleRedisConfig {
public
void
setCommandTimeout
(
int
commandTimeout
)
{
this
.
commandTimeout
=
commandTimeout
;
}
@Override
public
String
toString
()
{
return
String
.
format
(
"[SampleRedisConfig] expireSeconds: %d, clusterNodes: %s, commandTimeout: %d"
,
expireSeconds
,
clusterNodes
,
commandTimeout
);
}
}
apollo-demo/src/main/java/com/ctrip/framework/apollo/demo/spring/springBootDemo/refresh/SpringBootApolloRefreshConfig.java
0 → 100644
浏览文件 @
84053f70
package
com.ctrip.framework.apollo.demo.spring.springBootDemo.refresh
;
import
com.ctrip.framework.apollo.Config
;
import
com.ctrip.framework.apollo.ConfigChangeListener
;
import
com.ctrip.framework.apollo.demo.spring.common.refresh.ApolloRefreshConfig
;
import
com.ctrip.framework.apollo.demo.spring.springBootDemo.config.SampleRedisConfig
;
import
com.ctrip.framework.apollo.model.ConfigChangeEvent
;
import
com.ctrip.framework.apollo.spring.annotation.ApolloConfig
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.cloud.context.scope.refresh.RefreshScope
;
import
org.springframework.stereotype.Component
;
import
javax.annotation.PostConstruct
;
/**
* @author Jason Song(song_s@ctrip.com)
*/
@Component
public
class
SpringBootApolloRefreshConfig
implements
ConfigChangeListener
{
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
SpringBootApolloRefreshConfig
.
class
);
@Autowired
private
ApolloRefreshConfig
apolloRefreshConfig
;
@Autowired
private
SampleRedisConfig
sampleRedisConfig
;
@ApolloConfig
private
Config
config
;
@Autowired
private
RefreshScope
refreshScope
;
@PostConstruct
private
void
init
()
{
config
.
addChangeListener
(
this
);
}
@Override
public
void
onChange
(
ConfigChangeEvent
changeEvent
)
{
logger
.
info
(
"sampleRedisConfig before refresh {}"
,
sampleRedisConfig
.
toString
());
refreshScope
.
refresh
(
"sampleRedisConfig"
);
logger
.
info
(
"sampleRedisConfig after refresh {}"
,
sampleRedisConfig
.
toString
());
}
}
apollo-demo/src/main/resources/spring.xml
浏览文件 @
84053f70
...
...
@@ -2,14 +2,18 @@
<beans
xmlns=
"http://www.springframework.org/schema/beans"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xmlns:context=
"http://www.springframework.org/schema/context"
xmlns:aop=
"http://www.springframework.org/schema/aop"
xmlns:apollo=
"http://www.ctrip.com/schema/apollo"
xsi:schemaLocation=
"http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.ctrip.com/schema/apollo http://www.ctrip.com/schema/apollo.xsd"
>
<apollo:config
order=
"10"
/>
<apollo:config
namespaces=
"FX.apollo"
order=
"11"
/>
<bean
class=
"com.ctrip.framework.apollo.demo.spring.common.bean.NormalBean"
>
<bean
name=
"normalBean"
id=
"normalBean"
class=
"com.ctrip.framework.apollo.demo.spring.common.bean.NormalBean"
scope=
"refresh"
>
<aop:scoped-proxy
proxy-target-class=
"true"
/>
<property
name=
"batch"
value=
"${batch:100}"
/>
</bean>
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录