Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

增加了ApolloJsonValue来支持Json格式的配置项 #989

Merged
merged 4 commits into from
Mar 12, 2018

Conversation

weiguang-zz
Copy link
Contributor

@weiguang-zz weiguang-zz commented Mar 8, 2018

Features

  1. Support injecting Json values with @ApolloJsonValue, the supported format is the same as Spring @Value, such as @ApolloJsonValue("${someJsonPropertyKey}")
  2. Support auto updating injected values for @ApolloJsonValue

Usages

Suppose we have a type SomeObject, which has 2 properties: someString and someInt.

And we have a config as:

someJsonPropertyKey={"someString":"someValue", "someInt":10}

Then we can inject it on fields:

@ApolloJsonValue("${someJsonPropertyKey}")
private SomeObject someObject;

Or on methods:

@ApolloJsonValue("${someJsonPropertyKey}")
public void setJsonBeans(SomeObject someObject) {
  this.someObject = someObject;
}

Providing default value is suggested, such as:

@ApolloJsonValue("${someJsonPropertyKey:{\"someString\":\"someDefaultValue\", \"someInt\":10}}")
private SomeObject someObject;

2 抽离了一个公共父类ApolloProcessor,用来处理反射相关的逻辑。 ApolloJsonValueProcessor,ApolloAnnotationProcessor,SpringValueProcessor都继承它
3 在PropertySourceProcessor中注册自动更新的监听器AutoUpdateConfigChangeListener
4 SpringValue增加isJson字段,表示这个属性是否是Json类型的
5 增加了单元测试
@codecov-io
Copy link

codecov-io commented Mar 9, 2018

Codecov Report

Merging #989 into master will increase coverage by 0.37%.
The diff coverage is 91.37%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master     #989      +/-   ##
============================================
+ Coverage     48.27%   48.64%   +0.37%     
- Complexity     1647     1671      +24     
============================================
  Files           360      364       +4     
  Lines         10054    10144      +90     
  Branches       1012     1026      +14     
============================================
+ Hits           4854     4935      +81     
- Misses         4844     4847       +3     
- Partials        356      362       +6
Impacted Files Coverage Δ Complexity Δ
...pollo/spring/annotation/ApolloConfigRegistrar.java 100% <100%> (ø) 2 <0> (ø) ⬇️
.../spring/config/ConfigPropertySourcesProcessor.java 100% <100%> (ø) 3 <0> (ø) ⬇️
...apollo/spring/config/PropertySourcesProcessor.java 95.34% <100%> (-4.66%) 15 <5> (+3)
.../framework/apollo/spring/property/SpringValue.java 100% <100%> (ø) 19 <6> (+4) ⬆️
...rk/apollo/spring/property/SpringValueRegistry.java 100% <100%> (ø) 3 <3> (?)
...work/apollo/spring/annotation/ApolloProcessor.java 100% <100%> (ø) 8 <8> (?)
...o/spring/annotation/ApolloAnnotationProcessor.java 100% <100%> (ø) 7 <7> (-5) ⬇️
...ip/framework/apollo/internals/DefaultInjector.java 70.37% <100%> (+1.13%) 3 <0> (ø) ⬇️
...work/apollo/spring/property/PlaceholderHelper.java 81.53% <60%> (-3.92%) 24 <2> (+2)
...apollo/spring/annotation/SpringValueProcessor.java 84.61% <87.5%> (-1.82%) 17 <8> (-15)
... and 7 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a4a1d3a...5f5f45a. Read the comment docs.

Copy link
Member

@nobodyiam nobodyiam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good

@nobodyiam nobodyiam merged commit 40abd75 into apolloconfig:master Mar 12, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants