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
75878e16
Commit
75878e16
authored
Mar 08, 2017
by
张乐
Committed by
GitHub
Mar 08, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #560 from nobodyiam/apollo-spring-fix
minor fix for Spring
parents
6f30d521
9b06053c
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
9 deletions
+21
-9
ApolloAnnotationProcessor.java
...k/apollo/spring/annotation/ApolloAnnotationProcessor.java
+8
-1
PropertySourcesProcessor.java
...mework/apollo/spring/config/PropertySourcesProcessor.java
+13
-8
No files found.
apollo-client/src/main/java/com/ctrip/framework/apollo/spring/annotation/ApolloAnnotationProcessor.java
View file @
75878e16
...
...
@@ -9,6 +9,8 @@ import com.ctrip.framework.apollo.model.ConfigChangeEvent;
import
org.springframework.beans.BeansException
;
import
org.springframework.beans.factory.config.BeanPostProcessor
;
import
org.springframework.core.Ordered
;
import
org.springframework.core.PriorityOrdered
;
import
org.springframework.core.annotation.AnnotationUtils
;
import
org.springframework.util.ReflectionUtils
;
...
...
@@ -20,7 +22,7 @@ import java.lang.reflect.Method;
*
* @author Jason Song(song_s@ctrip.com)
*/
public
class
ApolloAnnotationProcessor
implements
BeanPostProcessor
{
public
class
ApolloAnnotationProcessor
implements
BeanPostProcessor
,
PriorityOrdered
{
@Override
public
Object
postProcessBeforeInitialization
(
Object
bean
,
String
beanName
)
throws
BeansException
{
Class
clazz
=
bean
.
getClass
();
...
...
@@ -80,4 +82,9 @@ public class ApolloAnnotationProcessor implements BeanPostProcessor {
}
}
@Override
public
int
getOrder
()
{
//make it as late as possible
return
Ordered
.
LOWEST_PRECEDENCE
;
}
}
apollo-client/src/main/java/com/ctrip/framework/apollo/spring/config/PropertySourcesProcessor.java
View file @
75878e16
...
...
@@ -11,6 +11,8 @@ import org.springframework.beans.BeansException;
import
org.springframework.beans.factory.config.BeanFactoryPostProcessor
;
import
org.springframework.beans.factory.config.ConfigurableListableBeanFactory
;
import
org.springframework.context.EnvironmentAware
;
import
org.springframework.core.Ordered
;
import
org.springframework.core.PriorityOrdered
;
import
org.springframework.core.env.CompositePropertySource
;
import
org.springframework.core.env.ConfigurableEnvironment
;
import
org.springframework.core.env.Environment
;
...
...
@@ -24,10 +26,9 @@ import java.util.concurrent.atomic.AtomicBoolean;
*
* @author Jason Song(song_s@ctrip.com)
*/
public
class
PropertySourcesProcessor
implements
BeanFactoryPostProcessor
,
EnvironmentAware
{
public
class
PropertySourcesProcessor
implements
BeanFactoryPostProcessor
,
EnvironmentAware
,
PriorityOrdered
{
private
static
final
String
APOLLO_PROPERTY_SOURCE_NAME
=
"ApolloPropertySources"
;
private
static
final
Multimap
<
Integer
,
String
>
NAMESPACE_NAMES
=
HashMultimap
.
create
();
private
static
final
AtomicBoolean
PROPERTY_SOURCES_INITIALIZED
=
new
AtomicBoolean
(
false
);
private
ConfigurableEnvironment
environment
;
...
...
@@ -37,15 +38,14 @@ public class PropertySourcesProcessor implements BeanFactoryPostProcessor, Envir
@Override
public
void
postProcessBeanFactory
(
ConfigurableListableBeanFactory
beanFactory
)
throws
BeansException
{
if
(!
PROPERTY_SOURCES_INITIALIZED
.
compareAndSet
(
false
,
true
))
{
//already initialized
return
;
}
initializePropertySources
();
}
protected
void
initializePropertySources
()
{
if
(
environment
.
getPropertySources
().
contains
(
APOLLO_PROPERTY_SOURCE_NAME
))
{
//already initialized
return
;
}
CompositePropertySource
composite
=
new
CompositePropertySource
(
APOLLO_PROPERTY_SOURCE_NAME
);
//sort by order asc
...
...
@@ -72,6 +72,11 @@ public class PropertySourcesProcessor implements BeanFactoryPostProcessor, Envir
//only for test
private
static
void
reset
()
{
NAMESPACE_NAMES
.
clear
();
PROPERTY_SOURCES_INITIALIZED
.
set
(
false
);
}
@Override
public
int
getOrder
()
{
//make it as early as possible
return
Ordered
.
HIGHEST_PRECEDENCE
;
}
}
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