Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
wrr-cat
apollo
提交
05acc044
apollo
项目概览
wrr-cat
/
apollo
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
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,发现更多精彩内容 >>
提交
05acc044
编写于
3月 03, 2018
作者:
N
nobodyiam
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
use ApplicationContextInitializer instead of SpringApplicationRunListener for better compatibility
上级
a81c9e49
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
18 addition
and
37 deletion
+18
-37
apollo-client/src/main/java/com/ctrip/framework/apollo/spring/boot/ApolloApplicationContextInitializer.java
...ollo/spring/boot/ApolloApplicationContextInitializer.java
+6
-33
apollo-client/src/main/resources/META-INF/spring.factories
apollo-client/src/main/resources/META-INF/spring.factories
+2
-2
apollo-demo/src/main/java/com/ctrip/framework/apollo/demo/spring/springBootDemo/SpringBootSampleApplication.java
...mo/spring/springBootDemo/SpringBootSampleApplication.java
+10
-2
未找到文件。
apollo-client/src/main/java/com/ctrip/framework/apollo/spring/boot/Apollo
SpringApplicationRunListen
er.java
→
apollo-client/src/main/java/com/ctrip/framework/apollo/spring/boot/Apollo
ApplicationContextInitializ
er.java
浏览文件 @
05acc044
...
...
@@ -6,16 +6,12 @@ import com.ctrip.framework.apollo.build.ApolloInjector;
import
com.ctrip.framework.apollo.core.ConfigConsts
;
import
com.ctrip.framework.apollo.spring.config.ConfigPropertySourceFactory
;
import
com.ctrip.framework.apollo.spring.config.PropertySourcesConstants
;
import
com.ctrip.framework.apollo.spring.config.ConfigPropertySource
;
import
com.google.common.base.Splitter
;
import
java.util.List
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.SpringApplicationRunListener
;
import
org.springframework.context.ApplicationContextInitializer
;
import
org.springframework.context.ConfigurableApplicationContext
;
import
org.springframework.core.Ordered
;
import
org.springframework.core.PriorityOrdered
;
import
org.springframework.core.env.CompositePropertySource
;
import
org.springframework.core.env.ConfigurableEnvironment
;
...
...
@@ -36,28 +32,16 @@ import org.springframework.core.env.ConfigurableEnvironment;
* apollo.bootstrap.namespaces = application,FX.apollo
* </pre>
*/
public
class
Apollo
SpringApplicationRunListener
implements
SpringApplicationRunListener
,
PriorityOrdered
{
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
Apollo
SpringApplicationRunListen
er
.
class
);
public
class
Apollo
ApplicationContextInitializer
implements
ApplicationContextInitializer
<
ConfigurableApplicationContext
>
{
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
Apollo
ApplicationContextInitializ
er
.
class
);
private
static
final
Splitter
NAMESPACE_SPLITTER
=
Splitter
.
on
(
","
).
omitEmptyStrings
().
trimResults
();
private
final
ConfigPropertySourceFactory
configPropertySourceFactory
=
ApolloInjector
.
getInstance
(
ConfigPropertySourceFactory
.
class
);
public
ApolloSpringApplicationRunListener
(
SpringApplication
application
,
String
[]
args
)
{
//ignore
}
public
void
starting
()
{
}
public
void
started
()
{
}
public
void
environmentPrepared
(
ConfigurableEnvironment
environment
)
{
}
public
void
contextPrepared
(
ConfigurableApplicationContext
context
)
{
@Override
public
void
initialize
(
ConfigurableApplicationContext
context
)
{
ConfigurableEnvironment
environment
=
context
.
getEnvironment
();
String
enabled
=
environment
.
getProperty
(
PropertySourcesConstants
.
APOLLO_BOOTSTRAP_ENABLED
,
"false"
);
if
(!
Boolean
.
valueOf
(
enabled
))
{
...
...
@@ -84,15 +68,4 @@ public class ApolloSpringApplicationRunListener implements SpringApplicationRunL
environment
.
getPropertySources
().
addFirst
(
composite
);
}
public
void
contextLoaded
(
ConfigurableApplicationContext
context
)
{
}
public
void
finished
(
ConfigurableApplicationContext
configurableApplicationContext
,
Throwable
throwable
)
{
}
public
int
getOrder
()
{
return
Ordered
.
LOWEST_PRECEDENCE
;
}
}
apollo-client/src/main/resources/META-INF/spring.factories
浏览文件 @
05acc044
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
com.ctrip.framework.apollo.spring.boot.ApolloAutoConfiguration
org.springframework.
boot.SpringApplicationRunListen
er=\
com.ctrip.framework.apollo.spring.boot.Apollo
SpringApplicationRunListen
er
org.springframework.
context.ApplicationContextInitializ
er=\
com.ctrip.framework.apollo.spring.boot.Apollo
ApplicationContextInitializ
er
apollo-demo/src/main/java/com/ctrip/framework/apollo/demo/spring/springBootDemo/SpringBootSampleApplication.java
浏览文件 @
05acc044
...
...
@@ -5,6 +5,7 @@ import java.io.BufferedReader;
import
java.io.IOException
;
import
java.io.InputStreamReader
;
import
org.springframework.beans.factory.NoSuchBeanDefinitionException
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
import
org.springframework.boot.builder.SpringApplicationBuilder
;
import
org.springframework.context.ApplicationContext
;
...
...
@@ -24,7 +25,12 @@ public class SpringBootSampleApplication {
public
static
void
main
(
String
[]
args
)
throws
IOException
{
ApplicationContext
context
=
new
SpringApplicationBuilder
(
SpringBootSampleApplication
.
class
).
run
(
args
);
AnnotatedBean
annotatedBean
=
context
.
getBean
(
AnnotatedBean
.
class
);
SampleRedisConfig
redisConfig
=
context
.
getBean
(
SampleRedisConfig
.
class
);
SampleRedisConfig
redisConfig
=
null
;
try
{
redisConfig
=
context
.
getBean
(
SampleRedisConfig
.
class
);
}
catch
(
NoSuchBeanDefinitionException
ex
)
{
System
.
out
.
println
(
"SampleRedisConfig is null, 'redis.cache.enabled' must have been set to false."
);
}
System
.
out
.
println
(
"SpringBootSampleApplication Demo. Input any key except quit to print the values. Input quit to exit."
);
while
(
true
)
{
...
...
@@ -35,7 +41,9 @@ public class SpringBootSampleApplication {
}
System
.
out
.
println
(
annotatedBean
.
toString
());
if
(
redisConfig
!=
null
)
{
System
.
out
.
println
(
redisConfig
.
toString
());
}
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录