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
9238f302
Commit
9238f302
authored
Oct 02, 2018
by
nobodyiam
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix #1482
parent
55aeeba0
Changes
3
Hide 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 @
9238f302
package
com
.
ctrip
.
framework
.
apollo
.
spring
.
annotation
;
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.context.annotation.ImportBeanDefinitionRegistrar
;
import
org.springframework.context.support.PropertySourcesPlaceholderConfigurer
;
...
...
@@ -23,8 +25,12 @@ public class ApolloConfigRegistrar implements ImportBeanDefinitionRegistrar {
int
order
=
attributes
.
getNumber
(
"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
(),
PropertySourcesPlaceholderConfigurer
.
class
);
PropertySourcesPlaceholderConfigurer
.
class
,
propertySourcesPlaceholderPropertyValues
);
BeanRegistrationUtil
.
registerBeanDefinitionIfNotExists
(
registry
,
PropertySourcesProcessor
.
class
.
getName
(),
PropertySourcesProcessor
.
class
);
...
...
apollo-client/src/main/java/com/ctrip/framework/apollo/spring/config/ConfigPropertySourcesProcessor.java
View file @
9238f302
...
...
@@ -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.property.SpringValueDefinitionProcessor
;
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.factory.support.BeanDefinitionRegistry
;
import
org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor
;
...
...
@@ -21,8 +23,12 @@ public class ConfigPropertySourcesProcessor extends PropertySourcesProcessor
@Override
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
(),
PropertySourcesPlaceholderConfigurer
.
class
);
PropertySourcesPlaceholderConfigurer
.
class
,
propertySourcesPlaceholderPropertyValues
);
BeanRegistrationUtil
.
registerBeanDefinitionIfNotExists
(
registry
,
ApolloAnnotationProcessor
.
class
.
getName
(),
ApolloAnnotationProcessor
.
class
);
BeanRegistrationUtil
.
registerBeanDefinitionIfNotExists
(
registry
,
SpringValueProcessor
.
class
.
getName
(),
SpringValueProcessor
.
class
);
...
...
apollo-client/src/main/java/com/ctrip/framework/apollo/spring/util/BeanRegistrationUtil.java
View file @
9238f302
package
com
.
ctrip
.
framework
.
apollo
.
spring
.
util
;
import
java.util.Map
;
import
java.util.Objects
;
import
org.springframework.beans.factory.config.BeanDefinition
;
...
...
@@ -11,7 +12,12 @@ import org.springframework.beans.factory.support.BeanDefinitionRegistry;
*/
public
class
BeanRegistrationUtil
{
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
))
{
return
false
;
}
...
...
@@ -25,9 +31,18 @@ public class BeanRegistrationUtil {
}
}
BeanDefinition
annotationProcessor
=
BeanDefinitionBuilder
.
genericBeanDefinition
(
beanClass
).
getBeanDefinition
();
registry
.
registerBeanDefinition
(
beanName
,
annotationProcessor
);
BeanDefinition
beanDefinition
=
BeanDefinitionBuilder
.
genericBeanDefinition
(
beanClass
).
getBeanDefinition
();
if
(
extraPropertyValues
!=
null
)
{
for
(
Map
.
Entry
<
String
,
Object
>
entry
:
extraPropertyValues
.
entrySet
())
{
beanDefinition
.
getPropertyValues
().
add
(
entry
.
getKey
(),
entry
.
getValue
());
}
}
registry
.
registerBeanDefinition
(
beanName
,
beanDefinition
);
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