Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
apollo
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
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
Administrator
apollo
Commits
a8369f85
Unverified
Commit
a8369f85
authored
Oct 03, 2018
by
Jason Song
Committed by
GitHub
Oct 03, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1525 from nobodyiam/issue-1482
fix #1482
parents
55aeeba0
9238f302
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
32 additions
and
5 deletions
+32
-5
apollo-client/src/main/java/com/ctrip/framework/apollo/spring/annotation/ApolloConfigRegistrar.java
...ework/apollo/spring/annotation/ApolloConfigRegistrar.java
+7
-1
apollo-client/src/main/java/com/ctrip/framework/apollo/spring/config/ConfigPropertySourcesProcessor.java
.../apollo/spring/config/ConfigPropertySourcesProcessor.java
+7
-1
apollo-client/src/main/java/com/ctrip/framework/apollo/spring/util/BeanRegistrationUtil.java
...ip/framework/apollo/spring/util/BeanRegistrationUtil.java
+18
-3
No files found.
apollo-client/src/main/java/com/ctrip/framework/apollo/spring/annotation/ApolloConfigRegistrar.java
View file @
a8369f85
package
com
.
ctrip
.
framework
.
apollo
.
spring
.
annotation
;
package
com
.
ctrip
.
framework
.
apollo
.
spring
.
annotation
;
import
com.ctrip.framework.apollo.spring.property.SpringValueDefinitionProcessor
;
import
com.ctrip.framework.apollo.spring.property.SpringValueDefinitionProcessor
;
import
java.util.HashMap
;
import
java.util.Map
;
import
org.springframework.beans.factory.support.BeanDefinitionRegistry
;
import
org.springframework.beans.factory.support.BeanDefinitionRegistry
;
import
org.springframework.context.annotation.ImportBeanDefinitionRegistrar
;
import
org.springframework.context.annotation.ImportBeanDefinitionRegistrar
;
import
org.springframework.context.support.PropertySourcesPlaceholderConfigurer
;
import
org.springframework.context.support.PropertySourcesPlaceholderConfigurer
;
...
@@ -23,8 +25,12 @@ public class ApolloConfigRegistrar implements ImportBeanDefinitionRegistrar {
...
@@ -23,8 +25,12 @@ public class ApolloConfigRegistrar implements ImportBeanDefinitionRegistrar {
int
order
=
attributes
.
getNumber
(
"order"
);
int
order
=
attributes
.
getNumber
(
"order"
);
PropertySourcesProcessor
.
addNamespaces
(
Lists
.
newArrayList
(
namespaces
),
order
);
PropertySourcesProcessor
.
addNamespaces
(
Lists
.
newArrayList
(
namespaces
),
order
);
Map
<
String
,
Object
>
propertySourcesPlaceholderPropertyValues
=
new
HashMap
<>();
// to make sure the default PropertySourcesPlaceholderConfigurer's priority is higher than PropertyPlaceholderConfigurer
propertySourcesPlaceholderPropertyValues
.
put
(
"order"
,
0
);
BeanRegistrationUtil
.
registerBeanDefinitionIfNotExists
(
registry
,
PropertySourcesPlaceholderConfigurer
.
class
.
getName
(),
BeanRegistrationUtil
.
registerBeanDefinitionIfNotExists
(
registry
,
PropertySourcesPlaceholderConfigurer
.
class
.
getName
(),
PropertySourcesPlaceholderConfigurer
.
class
);
PropertySourcesPlaceholderConfigurer
.
class
,
propertySourcesPlaceholderPropertyValues
);
BeanRegistrationUtil
.
registerBeanDefinitionIfNotExists
(
registry
,
PropertySourcesProcessor
.
class
.
getName
(),
BeanRegistrationUtil
.
registerBeanDefinitionIfNotExists
(
registry
,
PropertySourcesProcessor
.
class
.
getName
(),
PropertySourcesProcessor
.
class
);
PropertySourcesProcessor
.
class
);
...
...
apollo-client/src/main/java/com/ctrip/framework/apollo/spring/config/ConfigPropertySourcesProcessor.java
View file @
a8369f85
...
@@ -3,6 +3,8 @@ package com.ctrip.framework.apollo.spring.config;
...
@@ -3,6 +3,8 @@ package com.ctrip.framework.apollo.spring.config;
import
com.ctrip.framework.apollo.spring.annotation.SpringValueProcessor
;
import
com.ctrip.framework.apollo.spring.annotation.SpringValueProcessor
;
import
com.ctrip.framework.apollo.spring.property.SpringValueDefinitionProcessor
;
import
com.ctrip.framework.apollo.spring.property.SpringValueDefinitionProcessor
;
import
com.ctrip.framework.apollo.spring.annotation.ApolloJsonValueProcessor
;
import
com.ctrip.framework.apollo.spring.annotation.ApolloJsonValueProcessor
;
import
java.util.HashMap
;
import
java.util.Map
;
import
org.springframework.beans.BeansException
;
import
org.springframework.beans.BeansException
;
import
org.springframework.beans.factory.support.BeanDefinitionRegistry
;
import
org.springframework.beans.factory.support.BeanDefinitionRegistry
;
import
org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor
;
import
org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor
;
...
@@ -21,8 +23,12 @@ public class ConfigPropertySourcesProcessor extends PropertySourcesProcessor
...
@@ -21,8 +23,12 @@ public class ConfigPropertySourcesProcessor extends PropertySourcesProcessor
@Override
@Override
public
void
postProcessBeanDefinitionRegistry
(
BeanDefinitionRegistry
registry
)
throws
BeansException
{
public
void
postProcessBeanDefinitionRegistry
(
BeanDefinitionRegistry
registry
)
throws
BeansException
{
Map
<
String
,
Object
>
propertySourcesPlaceholderPropertyValues
=
new
HashMap
<>();
// to make sure the default PropertySourcesPlaceholderConfigurer's priority is higher than PropertyPlaceholderConfigurer
propertySourcesPlaceholderPropertyValues
.
put
(
"order"
,
0
);
BeanRegistrationUtil
.
registerBeanDefinitionIfNotExists
(
registry
,
PropertySourcesPlaceholderConfigurer
.
class
.
getName
(),
BeanRegistrationUtil
.
registerBeanDefinitionIfNotExists
(
registry
,
PropertySourcesPlaceholderConfigurer
.
class
.
getName
(),
PropertySourcesPlaceholderConfigurer
.
class
);
PropertySourcesPlaceholderConfigurer
.
class
,
propertySourcesPlaceholderPropertyValues
);
BeanRegistrationUtil
.
registerBeanDefinitionIfNotExists
(
registry
,
ApolloAnnotationProcessor
.
class
.
getName
(),
BeanRegistrationUtil
.
registerBeanDefinitionIfNotExists
(
registry
,
ApolloAnnotationProcessor
.
class
.
getName
(),
ApolloAnnotationProcessor
.
class
);
ApolloAnnotationProcessor
.
class
);
BeanRegistrationUtil
.
registerBeanDefinitionIfNotExists
(
registry
,
SpringValueProcessor
.
class
.
getName
(),
SpringValueProcessor
.
class
);
BeanRegistrationUtil
.
registerBeanDefinitionIfNotExists
(
registry
,
SpringValueProcessor
.
class
.
getName
(),
SpringValueProcessor
.
class
);
...
...
apollo-client/src/main/java/com/ctrip/framework/apollo/spring/util/BeanRegistrationUtil.java
View file @
a8369f85
package
com
.
ctrip
.
framework
.
apollo
.
spring
.
util
;
package
com
.
ctrip
.
framework
.
apollo
.
spring
.
util
;
import
java.util.Map
;
import
java.util.Objects
;
import
java.util.Objects
;
import
org.springframework.beans.factory.config.BeanDefinition
;
import
org.springframework.beans.factory.config.BeanDefinition
;
...
@@ -12,6 +13,11 @@ import org.springframework.beans.factory.support.BeanDefinitionRegistry;
...
@@ -12,6 +13,11 @@ import org.springframework.beans.factory.support.BeanDefinitionRegistry;
public
class
BeanRegistrationUtil
{
public
class
BeanRegistrationUtil
{
public
static
boolean
registerBeanDefinitionIfNotExists
(
BeanDefinitionRegistry
registry
,
String
beanName
,
public
static
boolean
registerBeanDefinitionIfNotExists
(
BeanDefinitionRegistry
registry
,
String
beanName
,
Class
<?>
beanClass
)
{
Class
<?>
beanClass
)
{
return
registerBeanDefinitionIfNotExists
(
registry
,
beanName
,
beanClass
,
null
);
}
public
static
boolean
registerBeanDefinitionIfNotExists
(
BeanDefinitionRegistry
registry
,
String
beanName
,
Class
<?>
beanClass
,
Map
<
String
,
Object
>
extraPropertyValues
)
{
if
(
registry
.
containsBeanDefinition
(
beanName
))
{
if
(
registry
.
containsBeanDefinition
(
beanName
))
{
return
false
;
return
false
;
}
}
...
@@ -25,9 +31,18 @@ public class BeanRegistrationUtil {
...
@@ -25,9 +31,18 @@ public class BeanRegistrationUtil {
}
}
}
}
BeanDefinition
annotationProcessor
=
BeanDefinitionBuilder
.
genericBeanDefinition
(
beanClass
).
getBeanDefinition
();
BeanDefinition
beanDefinition
=
BeanDefinitionBuilder
.
genericBeanDefinition
(
beanClass
).
getBeanDefinition
();
registry
.
registerBeanDefinition
(
beanName
,
annotationProcessor
);
if
(
extraPropertyValues
!=
null
)
{
for
(
Map
.
Entry
<
String
,
Object
>
entry
:
extraPropertyValues
.
entrySet
())
{
beanDefinition
.
getPropertyValues
().
add
(
entry
.
getKey
(),
entry
.
getValue
());
}
}
registry
.
registerBeanDefinition
(
beanName
,
beanDefinition
);
return
true
;
return
true
;
}
}
}
}
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