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
05acc044
Commit
05acc044
authored
Mar 03, 2018
by
nobodyiam
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use ApplicationContextInitializer instead of SpringApplicationRunListener for better compatibility
parent
a81c9e49
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
18 additions
and
37 deletions
+18
-37
ApolloApplicationContextInitializer.java
...ollo/spring/boot/ApolloApplicationContextInitializer.java
+6
-33
spring.factories
apollo-client/src/main/resources/META-INF/spring.factories
+2
-2
SpringBootSampleApplication.java
...mo/spring/springBootDemo/SpringBootSampleApplication.java
+10
-2
No files found.
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
View file @
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
View file @
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
View file @
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
());
System
.
out
.
println
(
redisConfig
.
toString
());
if
(
redisConfig
!=
null
)
{
System
.
out
.
println
(
redisConfig
.
toString
());
}
}
}
}
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