├── .gitignore
├── LICENSE
├── README.md
├── README_zh.md
├── googlestyle-java.xml
├── pom.xml
└── src
├── main
├── java
│ └── com
│ │ └── alibaba
│ │ └── dubbo
│ │ └── spring
│ │ └── boot
│ │ ├── DubboAutoConfiguration.java
│ │ ├── DubboCommonAutoConfiguration.java
│ │ ├── DubboConsumerAutoConfiguration.java
│ │ ├── DubboProperties.java
│ │ ├── DubboProviderAutoConfiguration.java
│ │ ├── annotation
│ │ └── EnableDubboConfiguration.java
│ │ ├── bean
│ │ ├── ClassIdBean.java
│ │ └── DubboSpringBootStarterConstants.java
│ │ ├── context
│ │ └── event
│ │ │ └── DubboBannerApplicationListener.java
│ │ ├── health
│ │ └── DubboHealthIndicator.java
│ │ ├── listener
│ │ └── ConsumerSubscribeListener.java
│ │ └── server
│ │ └── DubboServer.java
└── resources
│ └── META-INF
│ ├── dubbo
│ └── com.alibaba.dubbo.rpc.InvokerListener
│ ├── spring.factories
│ └── spring.provides
└── test
└── java
└── com
└── alibaba
└── dubbo
└── spring
└── boot
├── Mock.java
└── testcase
└── ClassIdBeanTest.java
/.gitignore:
--------------------------------------------------------------------------------
1 | target/
2 | .settings/
3 | .project
4 | .classpath
5 | *iml
6 | .idea
7 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "{}"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright {yyyy} {name of copyright owner}
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | dubbo-spring-boot-starter [](https://maven-badges.herokuapp.com/maven-central/com.alibaba.spring.boot/dubbo-spring-boot-starter)
2 | ===================================
3 |
4 | [中文版文档](https://github.com/alibaba/dubbo-spring-boot-starter/blob/master/README_zh.md)
5 |
6 | Dubbo Spring Boot Starter. Dubbo official [dubbo-spring-boot-project](https://github.com/dubbo/dubbo-spring-boot-project)
7 |
8 | Support jdk version 1.6 or 1.6+
9 |
10 | (please import googlestyle-java.xml if you want to modify the code)
11 |
12 | ### How to publish dubbo
13 |
14 | * add Dependencies:
15 |
16 | ```xml
17 | <dependency>
18 | <groupId>com.alibaba.spring.boot</groupId>
19 | <artifactId>dubbo-spring-boot-starter</artifactId>
20 | <version>2.0.0</version>
21 | </dependency>
22 | ```
23 | * add dubbo configuration in application.properties, demo:
24 |
25 | ```properties
26 | spring.application.name=dubbo-spring-boot-starter
27 | spring.dubbo.server=true
28 | spring.dubbo.registry=N/A
29 | ```
30 |
31 | * then add `@EnableDubboConfiguration` on Spring Boot Application, indicates that dubbo is enabled.(web or non-web application can use dubbo provider)
32 |
33 | ```java
34 | @SpringBootApplication
35 | @EnableDubboConfiguration
36 | public class DubboProviderLauncher {
37 | //...
38 | }
39 | ```
40 |
41 | * code your dubbo service, add `@Service`(import com.alibaba.dubbo.config.annotation.Service) on your service class, and interfaceClass is the interface which will be published.
42 |
43 | ```java
44 | @Service(interfaceClass = IHelloService.class)
45 | @Component
46 | public class HelloServiceImpl implements IHelloService {
47 | //...
48 | }
49 | ```
50 |
51 | * Start Spring Boot.
52 |
53 |
54 | ### How to consume Dubbo
55 |
56 | * add Dependencies:
57 |
58 | ```xml
59 | <dependency>
60 | <groupId>com.alibaba.spring.boot</groupId>
61 | <artifactId>dubbo-spring-boot-starter</artifactId>
62 | <version>2.0.0</version>
63 | </dependency>
64 | ```
65 |
66 | * add dubbo configuration in application.properties, demo:
67 |
68 | ```properties
69 | spring.application.name=dubbo-spring-boot-starter
70 | ```
71 |
72 | * then add `@EnableDubboConfiguration` on Spring Boot Application
73 |
74 | ```java
75 | @SpringBootApplication
76 | @EnableDubboConfiguration
77 | public class DubboConsumerLauncher {
78 | //...
79 | }
80 | ```
81 |
82 | * injection interface by the `@Reference` annotation.
83 |
84 | ```java
85 | @Component
86 | public class HelloConsumer {
87 | @Reference(url = "dubbo://127.0.0.1:20880")
88 | private IHelloService iHelloService;
89 |
90 | }
91 | ```
92 |
93 | ### Reference
94 |
95 | * dubbo: http://dubbo.io
96 | * spring-boot: http://projects.spring.io/spring-boot
97 | * dubbo-spring-boot-project: https://github.com/dubbo/dubbo-spring-boot-project
98 |
--------------------------------------------------------------------------------
/README_zh.md:
--------------------------------------------------------------------------------
1 | dubbo-spring-boot-starter
2 | ===================================
3 |
4 | [English](https://github.com/alibaba/dubbo-spring-boot-starter/blob/master/README.md)
5 |
6 | Dubbo Spring Boot Starter。也可以关注dubbo官方的[dubbo-spring-boot-project](https://github.com/dubbo/dubbo-spring-boot-project)
7 |
8 | 支持jdk版本为1.6或者1.6+
9 |
10 | (在修改源码前,请导入googlestyle-java.xml以保证一致的代码格式)
11 |
12 | ### 如何发布dubbo服务
13 |
14 | * 添加依赖:
15 |
16 | ```xml
17 | <dependency>
18 | <groupId>com.alibaba.spring.boot</groupId>
19 | <artifactId>dubbo-spring-boot-starter</artifactId>
20 | <version>2.0.0</version>
21 | </dependency>
22 | ```
23 |
24 | * 在application.properties添加dubbo的相关配置信息,样例配置如下:
25 |
26 | ```properties
27 | spring.application.name=dubbo-spring-boot-starter
28 | spring.dubbo.server=true
29 | spring.dubbo.registry=N/A
30 | ```
31 |
32 | 注:这个配置只针对服务提供端,消费端不用指定协议,它自己会根据服务端的地址信息和@Reference注解去解析协议
33 |
34 | * 接下来在Spring Boot Application的上添加`@EnableDubboConfiguration`,表示要开启dubbo功能. (dubbo provider服务可以使用或者不使用web容器)
35 |
36 | ```java
37 | @SpringBootApplication
38 | @EnableDubboConfiguration
39 | public class DubboProviderLauncher {
40 | //...
41 | }
42 | ```
43 |
44 | * 编写你的dubbo服务,只需要添加要发布的服务实现上添加`@Service`(import com.alibaba.dubbo.config.annotation.Service)注解,其中interfaceClass是要发布服务的接口.
45 |
46 | ```java
47 | @Service(interfaceClass = IHelloService.class)
48 | @Component
49 | public class HelloServiceImpl implements IHelloService {
50 | //...
51 | }
52 | ```
53 |
54 | * 启动你的Spring Boot应用,观察控制台,可以看到dubbo启动相关信息.
55 |
56 |
57 | ### 如何消费Dubbo服务
58 |
59 | * 添加依赖:
60 |
61 | ```xml
62 | <dependency>
63 | <groupId>com.alibaba.spring.boot</groupId>
64 | <artifactId>dubbo-spring-boot-starter</artifactId>
65 | <version>2.0.0</version>
66 | </dependency>
67 | ```
68 |
69 | * 在application.properties添加dubbo的相关配置信息,样例配置如下:
70 |
71 | ```properties
72 | spring.application.name=dubbo-spring-boot-starter
73 | ```
74 |
75 | * 开启`@EnableDubboConfiguration`
76 |
77 | ```java
78 | @SpringBootApplication
79 | @EnableDubboConfiguration
80 | public class DubboConsumerLauncher {
81 | //...
82 | }
83 | ```
84 |
85 | * 通过`@Reference`注入需要使用的interface.
86 |
87 | ```java
88 | @Component
89 | public class HelloConsumer {
90 | @Reference(url = "dubbo://127.0.0.1:20880")
91 | private IHelloService iHelloService;
92 |
93 | }
94 | ```
95 |
96 | ### 参考文档
97 |
98 | * dubbo: http://dubbo.io
99 | * spring-boot: http://projects.spring.io/spring-boot
100 | * dubbo-spring-boot-project: https://github.com/dubbo/dubbo-spring-boot-project
101 |
--------------------------------------------------------------------------------
/googlestyle-java.xml:
--------------------------------------------------------------------------------
1 | <?xml version="1.0" encoding="UTF-8" standalone="no"?>
2 | <profiles version="12">
3 | <profile kind="CodeFormatterProfile" name="GoogleStyle" version="12">
4 | <setting id="org.eclipse.jdt.core.formatter.comment.insert_new_line_before_root_tags" value="insert"/>
5 | <setting id="org.eclipse.jdt.core.formatter.disabling_tag" value="@formatter:off"/>
6 | <setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_annotation" value="insert"/>
7 | <setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_parameters" value="do not insert"/>
8 | <setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_type_declaration" value="insert"/>
9 | <setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_arguments" value="insert"/>
10 | <setting id="org.eclipse.jdt.core.formatter.brace_position_for_anonymous_type_declaration" value="end_of_line"/>
11 | <setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_case" value="do not insert"/>
12 | <setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_brace_in_array_initializer" value="do not insert"/>
13 | <setting id="org.eclipse.jdt.core.formatter.comment.new_lines_at_block_boundaries" value="true"/>
14 | <setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_annotation_declaration" value="insert"/>
15 | <setting id="org.eclipse.jdt.core.formatter.insert_new_line_before_closing_brace_in_array_initializer" value="do not insert"/>
16 | <setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_annotation" value="do not insert"/>
17 | <setting id="org.eclipse.jdt.core.formatter.blank_lines_before_field" value="0"/>
18 | <setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_while" value="do not insert"/>
19 | <setting id="org.eclipse.jdt.core.formatter.use_on_off_tags" value="true"/>
20 | <setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_annotation_type_member_declaration" value="do not insert"/>
21 | <setting id="org.eclipse.jdt.core.formatter.insert_new_line_before_else_in_if_statement" value="do not insert"/>
22 | <setting id="org.eclipse.jdt.core.formatter.insert_space_after_prefix_operator" value="do not insert"/>
23 | <setting id="org.eclipse.jdt.core.formatter.keep_else_statement_on_same_line" value="false"/>
24 | <setting id="org.eclipse.jdt.core.formatter.insert_space_after_ellipsis" value="insert"/>
25 | <setting id="org.eclipse.jdt.core.formatter.comment.insert_new_line_for_parameter" value="do not insert"/>
26 | <setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_annotation_type_declaration" value="insert"/>
27 | <setting id="org.eclipse.jdt.core.formatter.indent_breaks_compare_to_cases" value="true"/>
28 | <setting id="org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation" value="do not insert"/>
29 | <setting id="org.eclipse.jdt.core.formatter.alignment_for_multiple_fields" value="16"/>
30 | <setting id="org.eclipse.jdt.core.formatter.alignment_for_expressions_in_array_initializer" value="16"/>
31 | <setting id="org.eclipse.jdt.core.formatter.alignment_for_conditional_expression" value="80"/>
32 | <setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_for" value="insert"/>
33 | <setting id="org.eclipse.jdt.core.formatter.insert_space_after_binary_operator" value="insert"/>
34 | <setting id="org.eclipse.jdt.core.formatter.insert_space_before_question_in_wildcard" value="do not insert"/>
35 | <setting id="org.eclipse.jdt.core.formatter.brace_position_for_array_initializer" value="end_of_line"/>
36 | <setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_enum_constant" value="do not insert"/>
37 | <setting id="org.eclipse.jdt.core.formatter.insert_new_line_before_finally_in_try_statement" value="do not insert"/>
38 | <setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_local_variable" value="insert"/>
39 | <setting id="org.eclipse.jdt.core.formatter.insert_new_line_before_catch_in_try_statement" value="do not insert"/>
40 | <setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_while" value="insert"/>
41 | <setting id="org.eclipse.jdt.core.formatter.blank_lines_after_package" value="1"/>
42 | <setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_parameters" value="insert"/>
43 | <setting id="org.eclipse.jdt.core.formatter.continuation_indentation" value="2"/>
44 | <setting id="org.eclipse.jdt.core.formatter.insert_space_after_postfix_operator" value="do not insert"/>
45 | <setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_method_invocation" value="16"/>
46 | <setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_arguments" value="do not insert"/>
47 | <setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_superinterfaces" value="do not insert"/>
48 | <setting id="org.eclipse.jdt.core.formatter.blank_lines_before_new_chunk" value="1"/>
49 | <setting id="org.eclipse.jdt.core.formatter.insert_space_before_binary_operator" value="insert"/>
50 | <setting id="org.eclipse.jdt.core.formatter.blank_lines_before_package" value="0"/>
51 | <setting id="org.eclipse.jdt.core.compiler.source" value="1.7"/>
52 | <setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_constant_arguments" value="insert"/>
53 | <setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_constructor_declaration" value="do not insert"/>
54 | <setting id="org.eclipse.jdt.core.formatter.comment.format_line_comments" value="true"/>
55 | <setting id="org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_arguments" value="do not insert"/>
56 | <setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_declarations" value="insert"/>
57 | <setting id="org.eclipse.jdt.core.formatter.join_wrapped_lines" value="true"/>
58 | <setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_block" value="insert"/>
59 | <setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_explicit_constructor_call" value="16"/>
60 | <setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_invocation_arguments" value="do not insert"/>
61 | <setting id="org.eclipse.jdt.core.formatter.blank_lines_before_member_type" value="0"/>
62 | <setting id="org.eclipse.jdt.core.formatter.align_type_members_on_columns" value="false"/>
63 | <setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_enum_constant" value="do not insert"/>
64 | <setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_for" value="do not insert"/>
65 | <setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_method_declaration" value="insert"/>
66 | <setting id="org.eclipse.jdt.core.formatter.alignment_for_selector_in_method_invocation" value="16"/>
67 | <setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_switch" value="do not insert"/>
68 | <setting id="org.eclipse.jdt.core.formatter.insert_space_after_unary_operator" value="do not insert"/>
69 | <setting id="org.eclipse.jdt.core.formatter.insert_space_after_colon_in_case" value="insert"/>
70 | <setting id="org.eclipse.jdt.core.formatter.comment.indent_parameter_description" value="false"/>
71 | <setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_method_declaration" value="do not insert"/>
72 | <setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_switch" value="do not insert"/>
73 | <setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_enum_declaration" value="insert"/>
74 | <setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_parameters" value="do not insert"/>
75 | <setting id="org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_block_comment" value="false"/>
76 | <setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_type_declaration" value="insert"/>
77 | <setting id="org.eclipse.jdt.core.formatter.lineSplit" value="100"/>
78 | <setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_if" value="insert"/>
79 | <setting id="org.eclipse.jdt.core.formatter.insert_space_between_brackets_in_array_type_reference" value="do not insert"/>
80 | <setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_parenthesized_expression" value="do not insert"/>
81 | <setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_explicitconstructorcall_arguments" value="do not insert"/>
82 | <setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_constructor_declaration" value="insert"/>
83 | <setting id="org.eclipse.jdt.core.formatter.blank_lines_before_first_class_body_declaration" value="0"/>
84 | <setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_method" value="insert"/>
85 | <setting id="org.eclipse.jdt.core.formatter.indentation.size" value="4"/>
86 | <setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_declaration" value="do not insert"/>
87 | <setting id="org.eclipse.jdt.core.formatter.enabling_tag" value="@formatter:on"/>
88 | <setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_enum_constant" value="do not insert"/>
89 | <setting id="org.eclipse.jdt.core.formatter.alignment_for_superclass_in_type_declaration" value="16"/>
90 | <setting id="org.eclipse.jdt.core.formatter.alignment_for_assignment" value="16"/>
91 | <setting id="org.eclipse.jdt.core.compiler.problem.assertIdentifier" value="error"/>
92 | <setting id="org.eclipse.jdt.core.formatter.tabulation.char" value="space"/>
93 | <setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_constructor_declaration_parameters" value="insert"/>
94 | <setting id="org.eclipse.jdt.core.formatter.insert_space_after_semicolon_in_try_resources" value="insert"/>
95 | <setting id="org.eclipse.jdt.core.formatter.insert_space_before_prefix_operator" value="do not insert"/>
96 | <setting id="org.eclipse.jdt.core.formatter.indent_statements_compare_to_body" value="true"/>
97 | <setting id="org.eclipse.jdt.core.formatter.blank_lines_before_method" value="1"/>
98 | <setting id="org.eclipse.jdt.core.formatter.wrap_outer_expressions_when_nested" value="true"/>
99 | <setting id="org.eclipse.jdt.core.formatter.format_guardian_clause_on_one_line" value="false"/>
100 | <setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_for" value="insert"/>
101 | <setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_cast" value="do not insert"/>
102 | <setting id="org.eclipse.jdt.core.formatter.alignment_for_parameters_in_constructor_declaration" value="16"/>
103 | <setting id="org.eclipse.jdt.core.formatter.insert_space_after_colon_in_labeled_statement" value="insert"/>
104 | <setting id="org.eclipse.jdt.core.formatter.brace_position_for_annotation_type_declaration" value="end_of_line"/>
105 | <setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_method_body" value="do not insert"/>
106 | <setting id="org.eclipse.jdt.core.formatter.alignment_for_method_declaration" value="0"/>
107 | <setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_method_invocation" value="do not insert"/>
108 | <setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_try" value="do not insert"/>
109 | <setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_bracket_in_array_allocation_expression" value="do not insert"/>
110 | <setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_enum_constant" value="insert"/>
111 | <setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_annotation" value="do not insert"/>
112 | <setting id="org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation_type_declaration" value="do not insert"/>
113 | <setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_declaration_throws" value="do not insert"/>
114 | <setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_if" value="do not insert"/>
115 | <setting id="org.eclipse.jdt.core.formatter.brace_position_for_switch" value="end_of_line"/>
116 | <setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_declaration_throws" value="insert"/>
117 | <setting id="org.eclipse.jdt.core.formatter.insert_space_before_parenthesized_expression_in_return" value="insert"/>
118 | <setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_annotation" value="do not insert"/>
119 | <setting id="org.eclipse.jdt.core.formatter.insert_space_after_question_in_conditional" value="insert"/>
120 | <setting id="org.eclipse.jdt.core.formatter.insert_space_after_question_in_wildcard" value="do not insert"/>
121 | <setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_try" value="do not insert"/>
122 | <setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_bracket_in_array_allocation_expression" value="do not insert"/>
123 | <setting id="org.eclipse.jdt.core.formatter.comment.preserve_white_space_between_code_and_line_comments" value="false"/>
124 | <setting id="org.eclipse.jdt.core.formatter.insert_space_before_parenthesized_expression_in_throw" value="insert"/>
125 | <setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_arguments" value="do not insert"/>
126 | <setting id="org.eclipse.jdt.core.compiler.problem.enumIdentifier" value="error"/>
127 | <setting id="org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_switch" value="true"/>
128 | <setting id="org.eclipse.jdt.core.formatter.insert_space_before_ellipsis" value="do not insert"/>
129 | <setting id="org.eclipse.jdt.core.formatter.brace_position_for_block" value="end_of_line"/>
130 | <setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_for_inits" value="do not insert"/>
131 | <setting id="org.eclipse.jdt.core.formatter.brace_position_for_method_declaration" value="end_of_line"/>
132 | <setting id="org.eclipse.jdt.core.formatter.compact_else_if" value="true"/>
133 | <setting id="org.eclipse.jdt.core.formatter.wrap_before_or_operator_multicatch" value="true"/>
134 | <setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_array_initializer" value="do not insert"/>
135 | <setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_for_increments" value="insert"/>
136 | <setting id="org.eclipse.jdt.core.formatter.format_line_comment_starting_on_first_column" value="true"/>
137 | <setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_bracket_in_array_reference" value="do not insert"/>
138 | <setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_field" value="insert"/>
139 | <setting id="org.eclipse.jdt.core.formatter.comment.indent_root_tags" value="true"/>
140 | <setting id="org.eclipse.jdt.core.formatter.brace_position_for_enum_constant" value="end_of_line"/>
141 | <setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_enum_declarations" value="do not insert"/>
142 | <setting id="org.eclipse.jdt.core.formatter.alignment_for_union_type_in_multicatch" value="16"/>
143 | <setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_explicitconstructorcall_arguments" value="insert"/>
144 | <setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_switch" value="insert"/>
145 | <setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_declaration_parameters" value="do not insert"/>
146 | <setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_superinterfaces" value="insert"/>
147 | <setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_allocation_expression" value="do not insert"/>
148 | <setting id="org.eclipse.jdt.core.formatter.tabulation.size" value="2"/>
149 | <setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_type_reference" value="do not insert"/>
150 | <setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_opening_brace_in_array_initializer" value="do not insert"/>
151 | <setting id="org.eclipse.jdt.core.formatter.insert_space_after_closing_brace_in_block" value="insert"/>
152 | <setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_reference" value="do not insert"/>
153 | <setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_enum_constant" value="do not insert"/>
154 | <setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_arguments" value="do not insert"/>
155 | <setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_constructor_declaration" value="do not insert"/>
156 | <setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_constructor_declaration_throws" value="do not insert"/>
157 | <setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_if" value="do not insert"/>
158 | <setting id="org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_javadoc_comment" value="false"/>
159 | <setting id="org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_constructor_declaration" value="16"/>
160 | <setting id="org.eclipse.jdt.core.formatter.insert_space_after_assignment_operator" value="insert"/>
161 | <setting id="org.eclipse.jdt.core.formatter.insert_space_before_assignment_operator" value="insert"/>
162 | <setting id="org.eclipse.jdt.core.formatter.indent_empty_lines" value="false"/>
163 | <setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_synchronized" value="do not insert"/>
164 | <setting id="org.eclipse.jdt.core.formatter.insert_space_after_closing_paren_in_cast" value="insert"/>
165 | <setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_declaration_parameters" value="insert"/>
166 | <setting id="org.eclipse.jdt.core.formatter.brace_position_for_block_in_case" value="end_of_line"/>
167 | <setting id="org.eclipse.jdt.core.formatter.number_of_empty_lines_to_preserve" value="3"/>
168 | <setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_method_declaration" value="do not insert"/>
169 | <setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_catch" value="do not insert"/>
170 | <setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_constructor_declaration" value="do not insert"/>
171 | <setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_method_invocation" value="do not insert"/>
172 | <setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_bracket_in_array_reference" value="do not insert"/>
173 | <setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_qualified_allocation_expression" value="16"/>
174 | <setting id="org.eclipse.jdt.core.formatter.insert_space_after_and_in_type_parameter" value="insert"/>
175 | <setting id="org.eclipse.jdt.core.compiler.compliance" value="1.7"/>
176 | <setting id="org.eclipse.jdt.core.formatter.continuation_indentation_for_array_initializer" value="2"/>
177 | <setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_brackets_in_array_allocation_expression" value="do not insert"/>
178 | <setting id="org.eclipse.jdt.core.formatter.insert_space_before_at_in_annotation_type_declaration" value="insert"/>
179 | <setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression" value="16"/>
180 | <setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_cast" value="do not insert"/>
181 | <setting id="org.eclipse.jdt.core.formatter.insert_space_before_unary_operator" value="do not insert"/>
182 | <setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_parameterized_type_reference" value="do not insert"/>
183 | <setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_anonymous_type_declaration" value="insert"/>
184 | <setting id="org.eclipse.jdt.core.formatter.keep_empty_array_initializer_on_one_line" value="false"/>
185 | <setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_enum_declaration" value="insert"/>
186 | <setting id="org.eclipse.jdt.core.formatter.keep_imple_if_on_one_line" value="false"/>
187 | <setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_constructor_declaration_parameters" value="do not insert"/>
188 | <setting id="org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_parameters" value="insert"/>
189 | <setting id="org.eclipse.jdt.core.formatter.insert_new_line_at_end_of_file_if_missing" value="insert"/>
190 | <setting id="org.eclipse.jdt.core.formatter.insert_space_after_colon_in_for" value="insert"/>
191 | <setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_labeled_statement" value="do not insert"/>
192 | <setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_parameterized_type_reference" value="do not insert"/>
193 | <setting id="org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_type_declaration" value="16"/>
194 | <setting id="org.eclipse.jdt.core.formatter.alignment_for_binary_expression" value="16"/>
195 | <setting id="org.eclipse.jdt.core.formatter.brace_position_for_enum_declaration" value="end_of_line"/>
196 | <setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_type" value="insert"/>
197 | <setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_while" value="do not insert"/>
198 | <setting id="org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode" value="enabled"/>
199 | <setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_try" value="insert"/>
200 | <setting id="org.eclipse.jdt.core.formatter.put_empty_statement_on_new_line" value="false"/>
201 | <setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_label" value="do not insert"/>
202 | <setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_parameter" value="do not insert"/>
203 | <setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_parameters" value="do not insert"/>
204 | <setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_invocation" value="do not insert"/>
205 | <setting id="org.eclipse.jdt.core.formatter.insert_new_line_before_while_in_do_statement" value="do not insert"/>
206 | <setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_enum_constant" value="16"/>
207 | <setting id="org.eclipse.jdt.core.formatter.comment.format_javadoc_comments" value="true"/>
208 | <setting id="org.eclipse.jdt.core.formatter.comment.line_length" value="100"/>
209 | <setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_package" value="insert"/>
210 | <setting id="org.eclipse.jdt.core.formatter.blank_lines_between_import_groups" value="1"/>
211 | <setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_enum_constant_arguments" value="do not insert"/>
212 | <setting id="org.eclipse.jdt.core.formatter.insert_space_before_semicolon" value="do not insert"/>
213 | <setting id="org.eclipse.jdt.core.formatter.brace_position_for_constructor_declaration" value="end_of_line"/>
214 | <setting id="org.eclipse.jdt.core.formatter.number_of_blank_lines_at_beginning_of_method_body" value="0"/>
215 | <setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_conditional" value="insert"/>
216 | <setting id="org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_type_header" value="true"/>
217 | <setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_annotation_type_member_declaration" value="do not insert"/>
218 | <setting id="org.eclipse.jdt.core.formatter.wrap_before_binary_operator" value="true"/>
219 | <setting id="org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_declaration_header" value="true"/>
220 | <setting id="org.eclipse.jdt.core.formatter.blank_lines_between_type_declarations" value="2"/>
221 | <setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_synchronized" value="do not insert"/>
222 | <setting id="org.eclipse.jdt.core.formatter.indent_statements_compare_to_block" value="true"/>
223 | <setting id="org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_enum_declaration" value="16"/>
224 | <setting id="org.eclipse.jdt.core.formatter.join_lines_in_comments" value="true"/>
225 | <setting id="org.eclipse.jdt.core.formatter.insert_space_before_question_in_conditional" value="insert"/>
226 | <setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_field_declarations" value="do not insert"/>
227 | <setting id="org.eclipse.jdt.core.formatter.alignment_for_compact_if" value="16"/>
228 | <setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_for_inits" value="insert"/>
229 | <setting id="org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_cases" value="true"/>
230 | <setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_array_initializer" value="insert"/>
231 | <setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_default" value="do not insert"/>
232 | <setting id="org.eclipse.jdt.core.formatter.insert_space_before_and_in_type_parameter" value="insert"/>
233 | <setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_constructor_declaration" value="do not insert"/>
234 | <setting id="org.eclipse.jdt.core.formatter.blank_lines_before_imports" value="0"/>
235 | <setting id="org.eclipse.jdt.core.formatter.insert_space_after_colon_in_assert" value="insert"/>
236 | <setting id="org.eclipse.jdt.core.formatter.comment.format_html" value="true"/>
237 | <setting id="org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_method_declaration" value="16"/>
238 | <setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_parameters" value="do not insert"/>
239 | <setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_allocation_expression" value="do not insert"/>
240 | <setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_anonymous_type_declaration" value="do not insert"/>
241 | <setting id="org.eclipse.jdt.core.formatter.insert_space_after_colon_in_conditional" value="insert"/>
242 | <setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_parameterized_type_reference" value="do not insert"/>
243 | <setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_for" value="do not insert"/>
244 | <setting id="org.eclipse.jdt.core.formatter.insert_space_before_postfix_operator" value="do not insert"/>
245 | <setting id="org.eclipse.jdt.core.formatter.comment.format_source_code" value="true"/>
246 | <setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_synchronized" value="insert"/>
247 | <setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_allocation_expression" value="insert"/>
248 | <setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_constructor_declaration_throws" value="insert"/>
249 | <setting id="org.eclipse.jdt.core.formatter.alignment_for_parameters_in_method_declaration" value="16"/>
250 | <setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_brace_in_array_initializer" value="do not insert"/>
251 | <setting id="org.eclipse.jdt.core.compiler.codegen.targetPlatform" value="1.7"/>
252 | <setting id="org.eclipse.jdt.core.formatter.alignment_for_resources_in_try" value="80"/>
253 | <setting id="org.eclipse.jdt.core.formatter.use_tabs_only_for_leading_indentations" value="false"/>
254 | <setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_annotation" value="16"/>
255 | <setting id="org.eclipse.jdt.core.formatter.comment.format_header" value="true"/>
256 | <setting id="org.eclipse.jdt.core.formatter.comment.format_block_comments" value="true"/>
257 | <setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_enum_constant" value="do not insert"/>
258 | <setting id="org.eclipse.jdt.core.formatter.alignment_for_enum_constants" value="0"/>
259 | <setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_block" value="insert"/>
260 | <setting id="org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_annotation_declaration_header" value="true"/>
261 | <setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_parenthesized_expression" value="do not insert"/>
262 | <setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_parenthesized_expression" value="do not insert"/>
263 | <setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_catch" value="do not insert"/>
264 | <setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_local_declarations" value="do not insert"/>
265 | <setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_switch" value="insert"/>
266 | <setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_for_increments" value="do not insert"/>
267 | <setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_method_invocation" value="do not insert"/>
268 | <setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_assert" value="insert"/>
269 | <setting id="org.eclipse.jdt.core.formatter.brace_position_for_type_declaration" value="end_of_line"/>
270 | <setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_array_initializer" value="insert"/>
271 | <setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_braces_in_array_initializer" value="do not insert"/>
272 | <setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_method_declaration" value="do not insert"/>
273 | <setting id="org.eclipse.jdt.core.formatter.insert_space_before_semicolon_in_for" value="do not insert"/>
274 | <setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_catch" value="insert"/>
275 | <setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_parameterized_type_reference" value="do not insert"/>
276 | <setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_field_declarations" value="insert"/>
277 | <setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_annotation" value="do not insert"/>
278 | <setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_parameterized_type_reference" value="insert"/>
279 | <setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_invocation_arguments" value="insert"/>
280 | <setting id="org.eclipse.jdt.core.formatter.comment.new_lines_at_javadoc_boundaries" value="true"/>
281 | <setting id="org.eclipse.jdt.core.formatter.blank_lines_after_imports" value="1"/>
282 | <setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_local_declarations" value="insert"/>
283 | <setting id="org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_constant_header" value="true"/>
284 | <setting id="org.eclipse.jdt.core.formatter.insert_space_after_semicolon_in_for" value="insert"/>
285 | <setting id="org.eclipse.jdt.core.formatter.never_indent_line_comments_on_first_column" value="false"/>
286 | <setting id="org.eclipse.jdt.core.formatter.insert_space_before_semicolon_in_try_resources" value="do not insert"/>
287 | <setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_arguments" value="do not insert"/>
288 | <setting id="org.eclipse.jdt.core.formatter.never_indent_block_comments_on_first_column" value="false"/>
289 | <setting id="org.eclipse.jdt.core.formatter.keep_then_statement_on_same_line" value="false"/>
290 | </profile>
291 | </profiles>
292 |
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 | <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2 | xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3 | <modelVersion>4.0.0</modelVersion>
4 |
5 | <groupId>com.alibaba.spring.boot</groupId>
6 | <artifactId>dubbo-spring-boot-starter</artifactId>
7 | <version>2.0.1-SNAPSHOT</version>
8 | <packaging>jar</packaging>
9 |
10 | <name>dubbo-spring-boot-starter</name>
11 | <description>Dubbo Spring Boot Starter</description>
12 | <url>https://github.com/alibaba/dubbo-spring-boot-starter</url>
13 |
14 | <properties>
15 | <!-- project -->
16 | <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
17 | <java.version>1.6</java.version>
18 |
19 | <!-- dependencies -->
20 | <spring-boot.version>1.5.10.RELEASE</spring-boot.version>
21 | <dubbo.version>2.6.0</dubbo.version>
22 |
23 | <!-- plugins -->
24 | <maven-compiler-plugin.version>3.7.0</maven-compiler-plugin.version>
25 | <maven-surefire-plugin.version>2.20.1</maven-surefire-plugin.version>
26 | <maven-source-plugin.version>3.0.1</maven-source-plugin.version>
27 | <maven-javadoc-plugin.version>3.0.0</maven-javadoc-plugin.version>
28 | <maven-gpg-plugin.version>1.6</maven-gpg-plugin.version>
29 | </properties>
30 |
31 | <dependencies>
32 | <dependency>
33 | <groupId>com.alibaba</groupId>
34 | <artifactId>dubbo</artifactId>
35 | <version>${dubbo.version}</version>
36 | </dependency>
37 | <dependency>
38 | <groupId>org.springframework.boot</groupId>
39 | <artifactId>spring-boot-starter-actuator</artifactId>
40 | </dependency>
41 | <dependency>
42 | <groupId>org.springframework.boot</groupId>
43 | <artifactId>spring-boot-starter-web</artifactId>
44 | <optional>true</optional>
45 | </dependency>
46 | <dependency>
47 | <groupId>org.springframework.boot</groupId>
48 | <artifactId>spring-boot-starter</artifactId>
49 | <optional>true</optional>
50 | </dependency>
51 | <dependency>
52 | <groupId>org.springframework.boot</groupId>
53 | <artifactId>spring-boot-configuration-processor</artifactId>
54 | <optional>true</optional>
55 | </dependency>
56 | <dependency>
57 | <groupId>junit</groupId>
58 | <artifactId>junit</artifactId>
59 | <scope>test</scope>
60 | </dependency>
61 | </dependencies>
62 |
63 | <dependencyManagement>
64 | <dependencies>
65 | <dependency>
66 | <groupId>org.springframework.boot</groupId>
67 | <artifactId>spring-boot-dependencies</artifactId>
68 | <version>${spring-boot.version}</version>
69 | <type>pom</type>
70 | <scope>import</scope>
71 | </dependency>
72 | </dependencies>
73 | </dependencyManagement>
74 |
75 | <build>
76 | <plugins>
77 | <plugin>
78 | <groupId>org.apache.maven.plugins</groupId>
79 | <artifactId>maven-compiler-plugin</artifactId>
80 | <version>${maven-compiler-plugin.version}</version>
81 | <configuration>
82 | <encoding>${project.build.sourceEncoding}</encoding>
83 | <source>${java.version}</source>
84 | <target>${java.version}</target>
85 | </configuration>
86 | </plugin>
87 | <plugin>
88 | <groupId>org.apache.maven.plugins</groupId>
89 | <artifactId>maven-surefire-plugin</artifactId>
90 | <version>${maven-surefire-plugin.version}</version>
91 | <configuration>
92 | <includes>
93 | <include>**/testcase/**/*.java</include>
94 | </includes>
95 | </configuration>
96 | </plugin>
97 | <plugin>
98 | <groupId>org.apache.maven.plugins</groupId>
99 | <artifactId>maven-source-plugin</artifactId>
100 | <version>${maven-source-plugin.version}</version>
101 | <executions>
102 | <execution>
103 | <id>attach-sources</id>
104 | <goals>
105 | <goal>jar-no-fork</goal>
106 | </goals>
107 | </execution>
108 | </executions>
109 | <configuration>
110 | <attach>true</attach>
111 | </configuration>
112 | </plugin>
113 | <plugin>
114 | <groupId>org.apache.maven.plugins</groupId>
115 | <artifactId>maven-javadoc-plugin</artifactId>
116 | <version>${maven-javadoc-plugin.version}</version>
117 | <executions>
118 | <execution>
119 | <id>attach-javadocs</id>
120 | <goals>
121 | <goal>jar</goal>
122 | </goals>
123 | </execution>
124 | </executions>
125 | <configuration>
126 | <skip>false</skip>
127 | <show>public</show>
128 | <charset>${project.build.sourceEncoding}</charset>
129 | <encoding>${project.build.sourceEncoding}</encoding>
130 | <docencoding>${project.build.sourceEncoding}</docencoding>
131 | <links>
132 | <link>http://docs.oracle.com/javase/6/docs/api</link>
133 | </links>
134 | </configuration>
135 | </plugin>
136 | <plugin>
137 | <artifactId>maven-gpg-plugin</artifactId>
138 | <version>${maven-gpg-plugin.version}</version>
139 | <configuration>
140 | <skip>false</skip>
141 | </configuration>
142 | <executions>
143 | <execution>
144 | <id>sign-artifacts</id>
145 | <phase>verify</phase>
146 | <goals>
147 | <goal>sign</goal>
148 | </goals>
149 | </execution>
150 | </executions>
151 | </plugin>
152 | </plugins>
153 | </build>
154 |
155 | <scm>
156 | <connection>scm:git:git@github.com:alibaba/dubbo-spring-boot-starter.git</connection>
157 | <developerConnection>scm:git:git@github.com:alibaba/dubbo-spring-boot-starter.git</developerConnection>
158 | <url>https://github.com/alibaba/dubbo-spring-boot-starter.git</url>
159 | </scm>
160 |
161 | <licenses>
162 | <license>
163 | <name>The Apache Software License, Version 2.0</name>
164 | <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
165 | <distribution>repo</distribution>
166 | <comments>A business-friendly OSS license</comments>
167 | </license>
168 | </licenses>
169 |
170 | <developers>
171 | <developer>
172 | <id>xionghui</id>
173 | <name>xionghui</name>
174 | <email>xionghui_coder@163.com</email>
175 | </developer>
176 | <developer>
177 | <id>fx1061076658</id>
178 | <name>吴福星</name>
179 | <email>1061076658@qq.com</email>
180 | </developer>
181 | <developer>
182 | <id>snakefor100</id>
183 | <name>牛俊龙</name>
184 | <email>540973185@qq.com</email>
185 | </developer>
186 | <developer>
187 | <id>libin8537</id>
188 | <name>李斌</name>
189 | <email>libin8537@qq.com</email>
190 | </developer>
191 | <developer>
192 | <id>edwin1215</id>
193 | <name>曹峻铭</name>
194 | <email>supercjm1215@163.com</email>
195 | </developer>
196 | <developer>
197 | <id>yanchang-gyc</id>
198 | <name>郭彦昌</name>
199 | <email>yanchang.gyc@gmail.com</email>
200 | </developer>
201 | <developer>
202 | <id>hanwangkun</id>
203 | <name>韩旺坤</name>
204 | <email>hanwangkun2006@126.com</email>
205 | </developer>
206 | <developer>
207 | <id>Ivan97</id>
208 | <name>张砚池</name>
209 | <email>yangkizhang@gmail.com</email>
210 | </developer>
211 | </developers>
212 |
213 | <distributionManagement>
214 | <snapshotRepository>
215 | <id>sonatype-nexus-snapshots</id>
216 | <name>Sonatype Nexus Snapshots</name>
217 | <url>https://oss.sonatype.org/content/repositories/snapshots/</url>
218 | </snapshotRepository>
219 | <repository>
220 | <id>sonatype-nexus-staging</id>
221 | <name>Nexus Release Repository</name>
222 | <url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
223 | </repository>
224 | </distributionManagement>
225 | </project>
226 |
--------------------------------------------------------------------------------
/src/main/java/com/alibaba/dubbo/spring/boot/DubboAutoConfiguration.java:
--------------------------------------------------------------------------------
1 | package com.alibaba.dubbo.spring.boot;
2 |
3 | import java.util.concurrent.CountDownLatch;
4 |
5 | import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
6 | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
7 | import org.springframework.boot.context.properties.EnableConfigurationProperties;
8 | import org.springframework.context.annotation.Bean;
9 | import org.springframework.context.annotation.Configuration;
10 |
11 | import com.alibaba.dubbo.spring.boot.health.DubboHealthIndicator;
12 | import com.alibaba.dubbo.spring.boot.server.DubboServer;
13 |
14 | /**
15 | * Dubbo configuration
16 | *
17 | * @author xionghui
18 | * @version 2.0.0
19 | * @since 1.0.0
20 | */
21 | @Configuration
22 | @EnableConfigurationProperties(DubboProperties.class)
23 | public class DubboAutoConfiguration {
24 |
25 | /**
26 | * Start a non-daemon thread
27 | *
28 | * @return DubboServer
29 | */
30 | @Bean
31 | @ConditionalOnMissingBean
32 | @ConditionalOnProperty(prefix = "spring.dubbo", name = "server", havingValue = "true")
33 | public DubboServer dubboServer() {
34 | final DubboServer dubboServer = new DubboServer();
35 | final CountDownLatch latch = new CountDownLatch(1);
36 | Thread awaitThread = new Thread("dubboServer") {
37 |
38 | @Override
39 | public void run() {
40 | latch.countDown();
41 | dubboServer.await();
42 | }
43 | };
44 | awaitThread.setContextClassLoader(this.getClass().getClassLoader());
45 | awaitThread.setDaemon(false);
46 | awaitThread.start();
47 | try {
48 | latch.await();
49 | } catch (InterruptedException e) {
50 | throw new IllegalStateException(e);
51 | }
52 |
53 | return dubboServer;
54 | }
55 |
56 | @Bean
57 | public DubboHealthIndicator dubboHealthIndicator() {
58 | return new DubboHealthIndicator();
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/src/main/java/com/alibaba/dubbo/spring/boot/DubboCommonAutoConfiguration.java:
--------------------------------------------------------------------------------
1 | package com.alibaba.dubbo.spring.boot;
2 |
3 | import java.util.ArrayList;
4 | import java.util.HashMap;
5 | import java.util.LinkedHashMap;
6 | import java.util.List;
7 | import java.util.Map;
8 |
9 | import org.springframework.core.env.Environment;
10 |
11 | import com.alibaba.dubbo.config.AbstractConfig;
12 | import com.alibaba.dubbo.config.ApplicationConfig;
13 | import com.alibaba.dubbo.config.ConsumerConfig;
14 | import com.alibaba.dubbo.config.ModuleConfig;
15 | import com.alibaba.dubbo.config.MonitorConfig;
16 | import com.alibaba.dubbo.config.ProtocolConfig;
17 | import com.alibaba.dubbo.config.ProviderConfig;
18 | import com.alibaba.dubbo.config.RegistryConfig;
19 |
20 | /**
21 | * Dubbo common configuration
22 | *
23 | * @author xionghui
24 | * @version 2.0.0
25 | * @since 2.0.0
26 | */
27 | public class DubboCommonAutoConfiguration {
28 | protected static Map<String, Map<String, AbstractConfig>> ID_CONFIG_MAP = null;
29 |
30 | protected static String APPLICATIONS_KEY = "applications";
31 | protected static String MODULES_KEY = "modules";
32 | protected static String REGISTRIES_KEY = "registries";
33 | protected static String PROTOCOLS_KEY = "protocols";
34 | protected static String MONITORS_KEY = "monitors";
35 | protected static String PROVIDERS_KEY = "providers";
36 | protected static String CONSUMERS_KEY = "consumers";
37 |
38 | protected void initIdConfigMap(DubboProperties dubboProperties) {
39 | if (ID_CONFIG_MAP != null) {
40 | return;
41 | }
42 | synchronized (DubboCommonAutoConfiguration.class) {
43 | // double check
44 | if (DubboCommonAutoConfiguration.ID_CONFIG_MAP != null) {
45 | return;
46 | }
47 | DubboCommonAutoConfiguration.ID_CONFIG_MAP =
48 | new HashMap<String, Map<String, AbstractConfig>>();
49 | Map<String, AbstractConfig> applications = new LinkedHashMap<String, AbstractConfig>();
50 | DubboCommonAutoConfiguration.ID_CONFIG_MAP.put(APPLICATIONS_KEY, applications);
51 | Map<String, ApplicationConfig> applicationMap = dubboProperties.getApplications();
52 | if (applicationMap != null) {
53 | for (Map.Entry<String, ApplicationConfig> entry : applicationMap.entrySet()) {
54 | ApplicationConfig value = entry.getValue();
55 | applications.put(value.getId(), value);
56 | }
57 | }
58 |
59 | Map<String, AbstractConfig> modules = new LinkedHashMap<String, AbstractConfig>();
60 | DubboCommonAutoConfiguration.ID_CONFIG_MAP.put(MODULES_KEY, modules);
61 | Map<String, ModuleConfig> moduleMap = dubboProperties.getModules();
62 | if (moduleMap != null) {
63 | for (Map.Entry<String, ModuleConfig> entry : moduleMap.entrySet()) {
64 | ModuleConfig value = entry.getValue();
65 | modules.put(value.getId(), value);
66 | }
67 | }
68 |
69 | Map<String, AbstractConfig> registries = new LinkedHashMap<String, AbstractConfig>();
70 | DubboCommonAutoConfiguration.ID_CONFIG_MAP.put(REGISTRIES_KEY, registries);
71 | Map<String, RegistryConfig> registryMap = dubboProperties.getRegistries();
72 | if (registryMap != null) {
73 | for (Map.Entry<String, RegistryConfig> entry : registryMap.entrySet()) {
74 | RegistryConfig value = entry.getValue();
75 | registries.put(value.getId(), value);
76 | }
77 | }
78 |
79 | Map<String, AbstractConfig> protocols = new LinkedHashMap<String, AbstractConfig>();
80 | DubboCommonAutoConfiguration.ID_CONFIG_MAP.put(PROTOCOLS_KEY, protocols);
81 | Map<String, ProtocolConfig> protocolMap = dubboProperties.getProtocols();
82 | if (protocolMap != null) {
83 | for (Map.Entry<String, ProtocolConfig> entry : protocolMap.entrySet()) {
84 | ProtocolConfig value = entry.getValue();
85 | protocols.put(value.getId(), value);
86 | }
87 | }
88 |
89 | Map<String, AbstractConfig> monitors = new LinkedHashMap<String, AbstractConfig>();
90 | DubboCommonAutoConfiguration.ID_CONFIG_MAP.put(MONITORS_KEY, monitors);
91 | Map<String, MonitorConfig> monitorMap = dubboProperties.getMonitors();
92 | if (monitorMap != null) {
93 | for (Map.Entry<String, MonitorConfig> entry : monitorMap.entrySet()) {
94 | MonitorConfig value = entry.getValue();
95 | monitors.put(value.getId(), value);
96 | }
97 | }
98 |
99 | Map<String, AbstractConfig> providers = new LinkedHashMap<String, AbstractConfig>();
100 | DubboCommonAutoConfiguration.ID_CONFIG_MAP.put(PROVIDERS_KEY, providers);
101 | Map<String, ProviderConfig> providerMap = dubboProperties.getProviders();
102 | if (providerMap != null) {
103 | for (Map.Entry<String, ProviderConfig> entry : providerMap.entrySet()) {
104 | ProviderConfig value = entry.getValue();
105 | providers.put(value.getId(), value);
106 | }
107 | }
108 |
109 | Map<String, AbstractConfig> consumers = new LinkedHashMap<String, AbstractConfig>();
110 | DubboCommonAutoConfiguration.ID_CONFIG_MAP.put(CONSUMERS_KEY, consumers);
111 | Map<String, ConsumerConfig> consumerMap = dubboProperties.getConsumers();
112 | if (consumerMap != null) {
113 | for (Map.Entry<String, ConsumerConfig> entry : consumerMap.entrySet()) {
114 | ConsumerConfig value = entry.getValue();
115 | consumers.put(value.getId(), value);
116 | }
117 | }
118 | }
119 | }
120 |
121 | protected String buildErrorMsg(String... errors) {
122 | throw new UnsupportedOperationException("Not support");
123 | }
124 |
125 | protected ApplicationConfig parseApplication(String application, DubboProperties properties,
126 | Environment environment, String... errors) {
127 | ApplicationConfig applicationConfig = null;
128 | if (application == null || "".equals(application)) {
129 | applicationConfig = properties.getApplication();
130 | if (applicationConfig == null) {
131 | applicationConfig = new ApplicationConfig();
132 | applicationConfig.setName(environment.getProperty("spring.application.name"));
133 | }
134 | } else {
135 | application = environment.resolvePlaceholders(application);
136 | Map<String, AbstractConfig> applicationMap = ID_CONFIG_MAP.get(APPLICATIONS_KEY);
137 | applicationConfig = (ApplicationConfig) applicationMap.get(application);
138 | if (applicationConfig == null) {
139 | applicationConfig = properties.getApplications().get(application);
140 | if (applicationConfig == null) {
141 | throw new NullPointerException(this.buildErrorMsg(errors));
142 | }
143 | }
144 | }
145 | return applicationConfig;
146 | }
147 |
148 | protected ModuleConfig parseModule(String module, DubboProperties properties,
149 | Environment environment, String... errors) {
150 | ModuleConfig moduleConfig = null;
151 | if (module == null || "".equals(module)) {
152 | moduleConfig = properties.getModule();
153 | } else {
154 | module = environment.resolvePlaceholders(module);
155 | Map<String, AbstractConfig> moduleMap = ID_CONFIG_MAP.get(MODULES_KEY);
156 | moduleConfig = (ModuleConfig) moduleMap.get(module);
157 | if (moduleConfig == null) {
158 | moduleConfig = properties.getModules().get(module);
159 | if (moduleConfig == null) {
160 | throw new NullPointerException(this.buildErrorMsg(errors));
161 | }
162 | }
163 | }
164 | return moduleConfig;
165 | }
166 |
167 | protected List<RegistryConfig> parseRegistries(String[] registries, DubboProperties properties,
168 | Environment environment, String... errors) {
169 | List<RegistryConfig> registryList = null;
170 | if (registries == null || registries.length == 0) {
171 | RegistryConfig registry = properties.getRegistry();
172 | if (registry != null) {
173 | registryList = new ArrayList<RegistryConfig>();
174 | registryList.add(registry);
175 | }
176 | } else {
177 | for (int i = 0, len = registries.length; i < len; i++) {
178 | registries[i] = environment.resolvePlaceholders(registries[i]);
179 | }
180 | registryList = new ArrayList<RegistryConfig>();
181 | Map<String, AbstractConfig> registryMap = ID_CONFIG_MAP.get(REGISTRIES_KEY);
182 | for (String registry : registries) {
183 | RegistryConfig registryConfig = (RegistryConfig) registryMap.get(registry);
184 | if (registryConfig == null) {
185 | registryConfig = properties.getRegistries().get(registry);
186 | if (registryConfig == null) {
187 | List<String> errorList = new ArrayList<String>();
188 | if (errors != null) {
189 | for (String error : errors) {
190 | errorList.add(error);
191 | }
192 | }
193 | errorList.add(registry);
194 | throw new NullPointerException(this.buildErrorMsg(errorList.toArray(new String[0])));
195 | }
196 | }
197 | registryList.add(registryConfig);
198 | }
199 | }
200 | return registryList;
201 | }
202 |
203 | protected List<ProtocolConfig> parseProtocols(String[] protocols, DubboProperties properties,
204 | Environment environment, String... errors) {
205 | List<ProtocolConfig> protocolList = null;
206 | if (protocols != null && protocols.length == 0) {
207 | ProtocolConfig protocol = properties.getProtocol();
208 | if (protocol != null) {
209 | protocolList = new ArrayList<ProtocolConfig>();
210 | protocolList.add(protocol);
211 | }
212 | } else {
213 | for (int i = 0, len = protocols.length; i < len; i++) {
214 | protocols[i] = environment.resolvePlaceholders(protocols[i]);
215 | }
216 | protocolList = new ArrayList<ProtocolConfig>();
217 | Map<String, AbstractConfig> protocolMap = ID_CONFIG_MAP.get(PROTOCOLS_KEY);
218 | for (String protocol : protocols) {
219 | ProtocolConfig protocolConfig = (ProtocolConfig) protocolMap.get(protocol);
220 | if (protocolConfig == null) {
221 | protocolConfig = properties.getProtocols().get(protocol);
222 | if (protocolConfig == null) {
223 | List<String> errorList = new ArrayList<String>();
224 | if (errors != null) {
225 | for (String error : errors) {
226 | errorList.add(error);
227 | }
228 | }
229 | errorList.add(protocol);
230 | throw new NullPointerException(this.buildErrorMsg(errorList.toArray(new String[0])));
231 | }
232 | }
233 | protocolList.add(protocolConfig);
234 | }
235 | }
236 | return protocolList;
237 | }
238 |
239 | protected MonitorConfig parseMonitor(String monitor, DubboProperties properties,
240 | Environment environment, String... errors) {
241 | MonitorConfig monitorConfig = null;
242 | if (monitor == null || "".equals(monitor)) {
243 | monitorConfig = properties.getMonitor();
244 | } else {
245 | monitor = environment.resolvePlaceholders(monitor);
246 | Map<String, AbstractConfig> monitorMap = ID_CONFIG_MAP.get(MONITORS_KEY);
247 | monitorConfig = (MonitorConfig) monitorMap.get(monitor);
248 | if (monitorConfig == null) {
249 | monitorConfig = properties.getMonitors().get(monitor);
250 | if (monitorConfig == null) {
251 | throw new NullPointerException(this.buildErrorMsg(errors));
252 | }
253 | }
254 | }
255 | return monitorConfig;
256 | }
257 |
258 | protected ProviderConfig parseProvider(String provider, DubboProperties properties,
259 | Environment environment, String... errors) {
260 | ProviderConfig providerConfig = null;
261 | if (provider == null || "".equals(provider)) {
262 | providerConfig = properties.getProvider();
263 | } else {
264 | provider = environment.resolvePlaceholders(provider);
265 | Map<String, AbstractConfig> providerMap = ID_CONFIG_MAP.get(PROVIDERS_KEY);
266 | providerConfig = (ProviderConfig) providerMap.get(provider);
267 | if (providerConfig == null) {
268 | providerConfig = properties.getProviders().get(provider);
269 | if (providerConfig == null) {
270 | throw new NullPointerException(this.buildErrorMsg(errors));
271 | }
272 | }
273 | }
274 | return providerConfig;
275 | }
276 |
277 | protected ConsumerConfig parseConsumer(String consumer, DubboProperties properties,
278 | Environment environment, String... errors) {
279 | ConsumerConfig consumerConfig = null;
280 | if (consumer == null || "".equals(consumer)) {
281 | consumerConfig = properties.getConsumer();
282 | } else {
283 | consumer = environment.resolvePlaceholders(consumer);
284 | Map<String, AbstractConfig> consumerMap = ID_CONFIG_MAP.get(CONSUMERS_KEY);
285 | consumerConfig = (ConsumerConfig) consumerMap.get(consumer);
286 | if (consumerConfig == null) {
287 | consumerConfig = properties.getConsumers().get(consumer);
288 | if (consumerConfig == null) {
289 | throw new NullPointerException(this.buildErrorMsg(errors));
290 | }
291 | }
292 | }
293 | return consumerConfig;
294 | }
295 | }
296 |
--------------------------------------------------------------------------------
/src/main/java/com/alibaba/dubbo/spring/boot/DubboConsumerAutoConfiguration.java:
--------------------------------------------------------------------------------
1 | package com.alibaba.dubbo.spring.boot;
2 |
3 | import java.lang.reflect.Field;
4 | import java.util.Map;
5 | import java.util.concurrent.ConcurrentHashMap;
6 |
7 | import org.springframework.aop.support.AopUtils;
8 | import org.springframework.beans.BeansException;
9 | import org.springframework.beans.factory.BeanCreationException;
10 | import org.springframework.beans.factory.annotation.Autowired;
11 | import org.springframework.beans.factory.config.BeanPostProcessor;
12 | import org.springframework.boot.autoconfigure.AutoConfigureAfter;
13 | import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
14 | import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
15 | import org.springframework.boot.context.properties.EnableConfigurationProperties;
16 | import org.springframework.context.ApplicationContext;
17 | import org.springframework.context.annotation.Bean;
18 | import org.springframework.context.annotation.Configuration;
19 | import org.springframework.core.env.Environment;
20 |
21 | import com.alibaba.dubbo.config.annotation.Reference;
22 | import com.alibaba.dubbo.config.annotation.Service;
23 | import com.alibaba.dubbo.config.spring.ReferenceBean;
24 | import com.alibaba.dubbo.spring.boot.annotation.EnableDubboConfiguration;
25 | import com.alibaba.dubbo.spring.boot.bean.ClassIdBean;
26 |
27 | /**
28 | * DubboConsumerAutoConfiguration
29 | *
30 | * @author xionghui
31 | * @version 2.0.0
32 | * @since 1.0.0
33 | */
34 | @Configuration
35 | @ConditionalOnClass(Service.class)
36 | @ConditionalOnBean(annotation = EnableDubboConfiguration.class)
37 | @AutoConfigureAfter(DubboAutoConfiguration.class)
38 | @EnableConfigurationProperties(DubboProperties.class)
39 | public class DubboConsumerAutoConfiguration extends DubboCommonAutoConfiguration {
40 | private static final Map<ClassIdBean, Object> DUBBO_REFERENCES_MAP =
41 | new ConcurrentHashMap<ClassIdBean, Object>();
42 |
43 | @Autowired
44 | private ApplicationContext applicationContext;
45 | @Autowired
46 | private DubboProperties properties;
47 |
48 | public static Object getDubboReference(ClassIdBean classIdBean) {
49 | return DUBBO_REFERENCES_MAP.get(classIdBean);
50 | }
51 |
52 | @Bean
53 | public BeanPostProcessor beanPostProcessor() {
54 | return new BeanPostProcessor() {
55 |
56 | @Override
57 | public Object postProcessBeforeInitialization(Object bean, String beanName)
58 | throws BeansException {
59 | Class<?> objClz;
60 | if (AopUtils.isAopProxy(bean)) {
61 | objClz = AopUtils.getTargetClass(bean);
62 | } else {
63 | objClz = bean.getClass();
64 | }
65 |
66 | try {
67 | for (Field field : objClz.getDeclaredFields()) {
68 | Reference reference = field.getAnnotation(Reference.class);
69 | if (reference != null) {
70 | DubboConsumerAutoConfiguration.this
71 | .initIdConfigMap(DubboConsumerAutoConfiguration.this.properties);
72 | ReferenceBean<?> referenceBean =
73 | DubboConsumerAutoConfiguration.this.getConsumerBean(beanName, field, reference);
74 | Class<?> interfaceClass = referenceBean.getInterfaceClass();
75 | String group = referenceBean.getGroup();
76 | String version = referenceBean.getVersion();
77 | ClassIdBean classIdBean = new ClassIdBean(interfaceClass, group, version);
78 | Object dubboReference =
79 | DubboConsumerAutoConfiguration.DUBBO_REFERENCES_MAP.get(classIdBean);
80 | if (dubboReference == null) {
81 | synchronized (this) {
82 | // double check
83 | dubboReference =
84 | DubboConsumerAutoConfiguration.DUBBO_REFERENCES_MAP.get(classIdBean);
85 | if (dubboReference == null) {
86 | referenceBean.afterPropertiesSet();
87 | // dubboReference should not be null, otherwise it will cause
88 | // NullPointerException
89 | dubboReference = referenceBean.getObject();
90 | DubboConsumerAutoConfiguration.DUBBO_REFERENCES_MAP.put(classIdBean,
91 | dubboReference);
92 | }
93 | }
94 | }
95 | field.setAccessible(true);
96 | field.set(bean, dubboReference);
97 | }
98 | }
99 | } catch (Exception e) {
100 | throw new BeanCreationException(beanName, e);
101 | }
102 | return bean;
103 | }
104 |
105 | @Override
106 | public Object postProcessAfterInitialization(Object bean, String beanName)
107 | throws BeansException {
108 | return bean;
109 | }
110 | };
111 | }
112 |
113 | /**
114 | * init consumer bean
115 | *
116 | * @param interfaceClazz interfaceClazz
117 | * @param reference reference
118 | * @return ReferenceBean<T>
119 | * @throws BeansException BeansException
120 | */
121 | private <T> ReferenceBean<T> getConsumerBean(String beanName, Field field, Reference reference)
122 | throws BeansException {
123 | ReferenceBean<T> referenceBean = new ReferenceBean<T>(reference);
124 | if ((reference.interfaceClass() == null || reference.interfaceClass() == void.class)
125 | && (reference.interfaceName() == null || "".equals(reference.interfaceName()))) {
126 | referenceBean.setInterface(field.getType());
127 | }
128 |
129 | Environment environment = this.applicationContext.getEnvironment();
130 | String application = reference.application();
131 | referenceBean.setApplication(this.parseApplication(application, this.properties, environment,
132 | beanName, field.getName(), "application", application));
133 | String module = reference.module();
134 | referenceBean.setModule(this.parseModule(module, this.properties, environment, beanName,
135 | field.getName(), "module", module));
136 | String[] registries = reference.registry();
137 | referenceBean.setRegistries(this.parseRegistries(registries, this.properties, environment,
138 | beanName, field.getName(), "registry"));
139 | String monitor = reference.monitor();
140 | referenceBean.setMonitor(this.parseMonitor(monitor, this.properties, environment, beanName,
141 | field.getName(), "monitor", monitor));
142 | String consumer = reference.consumer();
143 | referenceBean.setConsumer(this.parseConsumer(consumer, this.properties, environment, beanName,
144 | field.getName(), "consumer", consumer));
145 |
146 | referenceBean.setApplicationContext(DubboConsumerAutoConfiguration.this.applicationContext);
147 | return referenceBean;
148 | }
149 |
150 | @Override
151 | protected String buildErrorMsg(String... errors) {
152 | if (errors == null || errors.length != 4) {
153 | return super.buildErrorMsg(errors);
154 | }
155 | return new StringBuilder().append("beanName=").append(errors[0]).append(", field=")
156 | .append(errors[1]).append(", ").append(errors[2]).append("=").append(errors[3])
157 | .append(" not found in multi configs").toString();
158 | }
159 | }
160 |
--------------------------------------------------------------------------------
/src/main/java/com/alibaba/dubbo/spring/boot/DubboProperties.java:
--------------------------------------------------------------------------------
1 | package com.alibaba.dubbo.spring.boot;
2 |
3 | import java.util.LinkedHashMap;
4 | import java.util.Map;
5 |
6 | import org.springframework.boot.context.properties.ConfigurationProperties;
7 |
8 | import com.alibaba.dubbo.config.ApplicationConfig;
9 | import com.alibaba.dubbo.config.ConsumerConfig;
10 | import com.alibaba.dubbo.config.ModuleConfig;
11 | import com.alibaba.dubbo.config.MonitorConfig;
12 | import com.alibaba.dubbo.config.ProtocolConfig;
13 | import com.alibaba.dubbo.config.ProviderConfig;
14 | import com.alibaba.dubbo.config.RegistryConfig;
15 | import org.springframework.boot.context.properties.NestedConfigurationProperty;
16 |
17 | /**
18 | * Dubbo properties
19 | *
20 | * @author xionghui
21 | * @author 韩旺坤
22 | * @version 2.0.0
23 | * @since 1.0.0
24 | */
25 | @ConfigurationProperties(prefix = "spring.dubbo")
26 | public class DubboProperties {
27 | /**
28 | * Indicates dubbo server
29 | */
30 | private boolean server;
31 |
32 | /**
33 | * {@link ApplicationConfig} property
34 | */
35 | @NestedConfigurationProperty
36 | private ApplicationConfig application;
37 |
38 | /**
39 | * {@link ModuleConfig} property
40 | */
41 | @NestedConfigurationProperty
42 | private ModuleConfig module;
43 |
44 | /**
45 | * {@link RegistryConfig} property
46 | */
47 | @NestedConfigurationProperty
48 | private RegistryConfig registry;
49 |
50 | /**
51 | * {@link ProtocolConfig} property
52 | */
53 | @NestedConfigurationProperty
54 | private ProtocolConfig protocol;
55 |
56 | /**
57 | * {@link MonitorConfig} property
58 | */
59 | @NestedConfigurationProperty
60 | private MonitorConfig monitor;
61 |
62 | /**
63 | * {@link ProviderConfig} property
64 | */
65 | @NestedConfigurationProperty
66 | private ProviderConfig provider;
67 |
68 | /**
69 | * {@link ConsumerConfig} property
70 | */
71 | @NestedConfigurationProperty
72 | private ConsumerConfig consumer;
73 |
74 | /**
75 | * Multiple {@link ApplicationConfig} property
76 | */
77 | private Map<String, ApplicationConfig> applications =
78 | new LinkedHashMap<String, ApplicationConfig>();
79 |
80 | /**
81 | * Multiple {@link ModuleConfig} property
82 | */
83 | private Map<String, ModuleConfig> modules = new LinkedHashMap<String, ModuleConfig>();
84 |
85 | /**
86 | * Multiple {@link RegistryConfig} property
87 | */
88 | private Map<String, RegistryConfig> registries = new LinkedHashMap<String, RegistryConfig>();
89 |
90 | /**
91 | * Multiple {@link ProtocolConfig} property
92 | */
93 | private Map<String, ProtocolConfig> protocols = new LinkedHashMap<String, ProtocolConfig>();
94 |
95 | /**
96 | * Multiple {@link MonitorConfig} property
97 | */
98 | private Map<String, MonitorConfig> monitors = new LinkedHashMap<String, MonitorConfig>();
99 |
100 | /**
101 | * Multiple {@link ProviderConfig} property
102 | */
103 | private Map<String, ProviderConfig> providers = new LinkedHashMap<String, ProviderConfig>();
104 |
105 | /**
106 | * Multiple {@link ConsumerConfig} property
107 | */
108 | private Map<String, ConsumerConfig> consumers = new LinkedHashMap<String, ConsumerConfig>();
109 |
110 | public boolean isServer() {
111 | return this.server;
112 | }
113 |
114 | public void setServer(boolean server) {
115 | this.server = server;
116 | }
117 |
118 | public ApplicationConfig getApplication() {
119 | return this.application;
120 | }
121 |
122 | public void setApplication(ApplicationConfig application) {
123 | this.application = application;
124 | }
125 |
126 | public ModuleConfig getModule() {
127 | return this.module;
128 | }
129 |
130 | public void setModule(ModuleConfig module) {
131 | this.module = module;
132 | }
133 |
134 | public RegistryConfig getRegistry() {
135 | return this.registry;
136 | }
137 |
138 | public void setRegistry(RegistryConfig registry) {
139 | this.registry = registry;
140 | }
141 |
142 | public ProtocolConfig getProtocol() {
143 | return this.protocol;
144 | }
145 |
146 | public void setProtocol(ProtocolConfig protocol) {
147 | this.protocol = protocol;
148 | }
149 |
150 | public MonitorConfig getMonitor() {
151 | return this.monitor;
152 | }
153 |
154 | public void setMonitor(MonitorConfig monitor) {
155 | this.monitor = monitor;
156 | }
157 |
158 | public ProviderConfig getProvider() {
159 | return this.provider;
160 | }
161 |
162 | public void setProvider(ProviderConfig provider) {
163 | this.provider = provider;
164 | }
165 |
166 | public ConsumerConfig getConsumer() {
167 | return this.consumer;
168 | }
169 |
170 | public void setConsumer(ConsumerConfig consumer) {
171 | this.consumer = consumer;
172 | }
173 |
174 | public Map<String, ApplicationConfig> getApplications() {
175 | return this.applications;
176 | }
177 |
178 | public void setApplications(Map<String, ApplicationConfig> applications) {
179 | this.applications = applications;
180 | }
181 |
182 | public Map<String, ModuleConfig> getModules() {
183 | return this.modules;
184 | }
185 |
186 | public void setModules(Map<String, ModuleConfig> modules) {
187 | this.modules = modules;
188 | }
189 |
190 | public Map<String, RegistryConfig> getRegistries() {
191 | return this.registries;
192 | }
193 |
194 | public void setRegistries(Map<String, RegistryConfig> registries) {
195 | this.registries = registries;
196 | }
197 |
198 | public Map<String, ProtocolConfig> getProtocols() {
199 | return this.protocols;
200 | }
201 |
202 | public void setProtocols(Map<String, ProtocolConfig> protocols) {
203 | this.protocols = protocols;
204 | }
205 |
206 | public Map<String, MonitorConfig> getMonitors() {
207 | return this.monitors;
208 | }
209 |
210 | public void setMonitors(Map<String, MonitorConfig> monitors) {
211 | this.monitors = monitors;
212 | }
213 |
214 | public Map<String, ProviderConfig> getProviders() {
215 | return this.providers;
216 | }
217 |
218 | public void setProviders(Map<String, ProviderConfig> providers) {
219 | this.providers = providers;
220 | }
221 |
222 | public Map<String, ConsumerConfig> getConsumers() {
223 | return this.consumers;
224 | }
225 |
226 | public void setConsumers(Map<String, ConsumerConfig> consumers) {
227 | this.consumers = consumers;
228 | }
229 |
230 | @Override
231 | public String toString() {
232 | return "DubboProperties [server=" + this.server + ", application=" + this.application
233 | + ", module=" + this.module + ", registry=" + this.registry + ", protocol=" + this.protocol
234 | + ", monitor=" + this.monitor + ", provider=" + this.provider + ", consumer="
235 | + this.consumer + ", applications=" + this.applications + ", modules=" + this.modules
236 | + ", registries=" + this.registries + ", protocols=" + this.protocols + ", monitors="
237 | + this.monitors + ", providers=" + this.providers + ", consumers=" + this.consumers + "]";
238 | }
239 | }
240 |
--------------------------------------------------------------------------------
/src/main/java/com/alibaba/dubbo/spring/boot/DubboProviderAutoConfiguration.java:
--------------------------------------------------------------------------------
1 | package com.alibaba.dubbo.spring.boot;
2 |
3 | import java.util.Map;
4 |
5 | import javax.annotation.PostConstruct;
6 |
7 | import org.springframework.beans.factory.annotation.Autowired;
8 | import org.springframework.boot.autoconfigure.AutoConfigureAfter;
9 | import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
10 | import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
11 | import org.springframework.boot.context.properties.EnableConfigurationProperties;
12 | import org.springframework.context.ApplicationContext;
13 | import org.springframework.context.annotation.Configuration;
14 | import org.springframework.core.env.Environment;
15 |
16 | import com.alibaba.dubbo.config.annotation.Service;
17 | import com.alibaba.dubbo.config.spring.ServiceBean;
18 | import com.alibaba.dubbo.spring.boot.annotation.EnableDubboConfiguration;
19 |
20 | /**
21 | * DubboProviderAutoConfiguration
22 | *
23 | * @author xionghui
24 | * @author 韩旺坤
25 | * @version 2.0.0
26 | * @since 1.0.0
27 | */
28 | @Configuration
29 | @ConditionalOnClass(Service.class)
30 | @ConditionalOnBean(annotation = EnableDubboConfiguration.class)
31 | @AutoConfigureAfter(DubboAutoConfiguration.class)
32 | @EnableConfigurationProperties(DubboProperties.class)
33 | public class DubboProviderAutoConfiguration extends DubboCommonAutoConfiguration {
34 | @Autowired
35 | private ApplicationContext applicationContext;
36 | @Autowired
37 | private DubboProperties properties;
38 |
39 | @PostConstruct
40 | public void init() throws Exception {
41 | Map<String, Object> beanMap = this.applicationContext.getBeansWithAnnotation(Service.class);
42 | if (beanMap != null && beanMap.size() > 0) {
43 | this.initIdConfigMap(this.properties);
44 | for (Map.Entry<String, Object> entry : beanMap.entrySet()) {
45 | this.initProviderBean(entry.getKey(), entry.getValue());
46 | }
47 | }
48 | }
49 |
50 | private void initProviderBean(String beanName, Object bean) throws Exception {
51 | Service service = this.applicationContext.findAnnotationOnBean(beanName, Service.class);
52 | ServiceBean<Object> serviceConfig = new ServiceBean<Object>(service);
53 | if ((service.interfaceClass() == null || service.interfaceClass() == void.class)
54 | && (service.interfaceName() == null || "".equals(service.interfaceName()))) {
55 | Class<?>[] interfaces = bean.getClass().getInterfaces();
56 | if (interfaces.length > 0) {
57 | serviceConfig.setInterface(interfaces[0]);
58 | }
59 | }
60 |
61 | Environment environment = this.applicationContext.getEnvironment();
62 | String application = service.application();
63 | serviceConfig.setApplication(this.parseApplication(application, this.properties, environment,
64 | beanName, "application", application));
65 | String module = service.module();
66 | serviceConfig.setModule(
67 | this.parseModule(module, this.properties, environment, beanName, "module", module));
68 | String[] registries = service.registry();
69 | serviceConfig.setRegistries(
70 | this.parseRegistries(registries, this.properties, environment, beanName, "registry"));
71 | String[] protocols = service.protocol();
72 | serviceConfig.setProtocols(
73 | this.parseProtocols(protocols, this.properties, environment, beanName, "registry"));
74 | String monitor = service.monitor();
75 | serviceConfig.setMonitor(
76 | this.parseMonitor(monitor, this.properties, environment, beanName, "monitor", monitor));
77 | String provider = service.provider();
78 | serviceConfig.setProvider(
79 | this.parseProvider(provider, this.properties, environment, beanName, "provider", provider));
80 |
81 | serviceConfig.setApplicationContext(this.applicationContext);
82 | serviceConfig.afterPropertiesSet();
83 | serviceConfig.setRef(bean);
84 | serviceConfig.export();
85 | }
86 |
87 | @Override
88 | protected String buildErrorMsg(String... errors) {
89 | if (errors == null || errors.length != 3) {
90 | return super.buildErrorMsg(errors);
91 | }
92 | return new StringBuilder().append("beanName=").append(errors[0]).append(", ").append(errors[1])
93 | .append("=").append(errors[2]).append(" not found in multi configs").toString();
94 | }
95 | }
96 |
--------------------------------------------------------------------------------
/src/main/java/com/alibaba/dubbo/spring/boot/annotation/EnableDubboConfiguration.java:
--------------------------------------------------------------------------------
1 | package com.alibaba.dubbo.spring.boot.annotation;
2 |
3 | import java.lang.annotation.Documented;
4 | import java.lang.annotation.ElementType;
5 | import java.lang.annotation.Retention;
6 | import java.lang.annotation.RetentionPolicy;
7 | import java.lang.annotation.Target;
8 |
9 | /**
10 | * Enable Dubbo (for provider or consumer) for spring boot application
11 | *
12 | * @author xionghui
13 | * @version 1.0.0
14 | * @since 1.0.0
15 | */
16 | @Target({ElementType.TYPE})
17 | @Retention(RetentionPolicy.RUNTIME)
18 | @Documented
19 | public @interface EnableDubboConfiguration {
20 |
21 | }
22 |
--------------------------------------------------------------------------------
/src/main/java/com/alibaba/dubbo/spring/boot/bean/ClassIdBean.java:
--------------------------------------------------------------------------------
1 | package com.alibaba.dubbo.spring.boot.bean;
2 |
3 | import java.io.Serializable;
4 |
5 | /**
6 | * Unique class.
7 | *
8 | * @author xionghui
9 | * @see #equals(Object)
10 | * @see #hashCode()
11 | * @version 1.0.0
12 | * @since 1.0.0
13 | */
14 | public class ClassIdBean implements Serializable {
15 | private static final long serialVersionUID = -6632632504039058978L;
16 |
17 | private final Class<?> interfaceClass;
18 | private final String group;
19 | private final String version;
20 |
21 | public ClassIdBean(Class<?> interfaceClass, String group, String version) {
22 | this.interfaceClass = interfaceClass;
23 | this.group = group;
24 | this.version = version;
25 | }
26 |
27 | public Class<?> getInterfaceClass() {
28 | return this.interfaceClass;
29 | }
30 |
31 | public String getGroup() {
32 | return this.group;
33 | }
34 |
35 | public String getVersion() {
36 | return this.version;
37 | }
38 |
39 | @Override
40 | public boolean equals(Object obj) {
41 | if (this == obj) {
42 | return true;
43 | }
44 | if (!(obj instanceof ClassIdBean)) {
45 | return false;
46 | }
47 | ClassIdBean classIdBean = (ClassIdBean) obj;
48 | if (this.interfaceClass == null ? classIdBean.interfaceClass != null
49 | : !this.interfaceClass.equals(classIdBean.interfaceClass)) {
50 | return false;
51 | }
52 | if (this.group == null ? classIdBean.group != null : !this.group.equals(classIdBean.group)) {
53 | return false;
54 | }
55 | return this.version == null ? classIdBean.version == null
56 | : this.version.equals(classIdBean.version);
57 | }
58 |
59 | @Override
60 | public int hashCode() {
61 | int hashCode = 17;
62 | hashCode = 31 * hashCode + (this.interfaceClass == null ? 0 : this.interfaceClass.hashCode());
63 | hashCode = 31 * hashCode + (this.group == null ? 0 : this.group.hashCode());
64 | hashCode = 31 * hashCode + (this.version == null ? 0 : this.version.hashCode());
65 | return hashCode;
66 | }
67 |
68 | @Override
69 | public String toString() {
70 | return "ClassIdBean [interfaceClass=" + this.interfaceClass + ", group=" + this.group
71 | + ", version=" + this.version + "]";
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/src/main/java/com/alibaba/dubbo/spring/boot/bean/DubboSpringBootStarterConstants.java:
--------------------------------------------------------------------------------
1 | package com.alibaba.dubbo.spring.boot.bean;
2 |
3 | /**
4 | * Constants defined.
5 | *
6 | * @author xionghui
7 | * @version 1.0.0
8 | * @since 1.0.0
9 | */
10 | public class DubboSpringBootStarterConstants {
11 |
12 | public static final String LINE_SEPARATOR = System.getProperty("line.separator");
13 |
14 | public static final String GROUP = "group";
15 |
16 | public static final String VERSION = "version";
17 | }
18 |
--------------------------------------------------------------------------------
/src/main/java/com/alibaba/dubbo/spring/boot/context/event/DubboBannerApplicationListener.java:
--------------------------------------------------------------------------------
1 | package com.alibaba.dubbo.spring.boot.context.event;
2 |
3 | import org.apache.commons.logging.Log;
4 | import org.apache.commons.logging.LogFactory;
5 | import org.springframework.boot.Banner;
6 | import org.springframework.boot.Banner.Mode;
7 | import org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent;
8 | import org.springframework.boot.logging.LoggingApplicationListener;
9 | import org.springframework.context.ApplicationListener;
10 | import org.springframework.core.annotation.Order;
11 |
12 | import com.alibaba.dubbo.common.Version;
13 | import com.alibaba.dubbo.qos.server.DubboLogo;
14 | import com.alibaba.dubbo.spring.boot.bean.DubboSpringBootStarterConstants;
15 |
16 | /**
17 | * Dubbo banner
18 | *
19 | * @author xionghui
20 | * @version 2.0.0
21 | * @since 2.0.0
22 | */
23 | @Order(LoggingApplicationListener.DEFAULT_ORDER)
24 | public class DubboBannerApplicationListener
25 | implements ApplicationListener<ApplicationEnvironmentPreparedEvent> {
26 | private static final Log logger = LogFactory.getLog(DubboBannerApplicationListener.class);
27 |
28 | private static Banner.Mode BANNER_MODE = Banner.Mode.CONSOLE;
29 |
30 | public static void setBANNER_MODE(Banner.Mode bANNER_MODE) {
31 | BANNER_MODE = bANNER_MODE;
32 | }
33 |
34 | @Override
35 | public void onApplicationEvent(ApplicationEnvironmentPreparedEvent event) {
36 | if (BANNER_MODE == Banner.Mode.OFF) {
37 | return;
38 | }
39 | String bannerText = this.buildBannerText();
40 | if (BANNER_MODE == Mode.CONSOLE) {
41 | System.out.print(bannerText);
42 | } else if (BANNER_MODE == Mode.LOG) {
43 | logger.info(bannerText);
44 | }
45 | }
46 |
47 | private String buildBannerText() {
48 | StringBuilder bannerTextBuilder = new StringBuilder();
49 | bannerTextBuilder.append(DubboSpringBootStarterConstants.LINE_SEPARATOR).append(DubboLogo.dubbo)
50 | .append(" :: Dubbo :: (v").append(Version.getVersion()).append(")")
51 | .append(DubboSpringBootStarterConstants.LINE_SEPARATOR);
52 | return bannerTextBuilder.toString();
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/src/main/java/com/alibaba/dubbo/spring/boot/health/DubboHealthIndicator.java:
--------------------------------------------------------------------------------
1 | package com.alibaba.dubbo.spring.boot.health;
2 |
3 | import org.springframework.boot.actuate.health.AbstractHealthIndicator;
4 | import org.springframework.boot.actuate.health.Health;
5 | import org.springframework.boot.actuate.health.Status;
6 |
7 | import com.alibaba.dubbo.rpc.service.EchoService;
8 | import com.alibaba.dubbo.spring.boot.DubboConsumerAutoConfiguration;
9 | import com.alibaba.dubbo.spring.boot.bean.ClassIdBean;
10 | import com.alibaba.dubbo.spring.boot.listener.ConsumerSubscribeListener;
11 |
12 | /**
13 | * Dubbo health indicator
14 | *
15 | * @author xionghui
16 | * @version 1.0.0
17 | * @since 1.0.0
18 | */
19 | public class DubboHealthIndicator extends AbstractHealthIndicator {
20 |
21 | @Override
22 | public void doHealthCheck(Health.Builder builder) throws Exception {
23 | boolean up = true;
24 | for (ClassIdBean classIdBean : ConsumerSubscribeListener.SUBSCRIBEDINTERFACES_SET) {
25 | Object service = DubboConsumerAutoConfiguration.getDubboReference(classIdBean);
26 | EchoService echoService = (EchoService) service;
27 | if (echoService != null) {
28 | try {
29 | echoService.$echo("Hello");
30 | builder.withDetail(classIdBean.toString(), Status.UP.getCode());
31 | } catch (Throwable t) {
32 | up = false;
33 | builder.withDetail(classIdBean.toString(),
34 | Status.DOWN.getCode() + ", message: " + t.getMessage());
35 | }
36 | }
37 | }
38 | if (up) {
39 | builder.up();
40 | } else {
41 | builder.down();
42 | }
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/src/main/java/com/alibaba/dubbo/spring/boot/listener/ConsumerSubscribeListener.java:
--------------------------------------------------------------------------------
1 | package com.alibaba.dubbo.spring.boot.listener;
2 |
3 | import java.util.Set;
4 |
5 | import com.alibaba.dubbo.common.URL;
6 | import com.alibaba.dubbo.common.extension.Activate;
7 | import com.alibaba.dubbo.common.utils.ConcurrentHashSet;
8 | import com.alibaba.dubbo.rpc.Invoker;
9 | import com.alibaba.dubbo.rpc.RpcException;
10 | import com.alibaba.dubbo.rpc.listener.InvokerListenerAdapter;
11 | import com.alibaba.dubbo.spring.boot.bean.ClassIdBean;
12 | import com.alibaba.dubbo.spring.boot.bean.DubboSpringBootStarterConstants;
13 |
14 | /**
15 | * Dubbo client invoker listener
16 | *
17 | * @author xionghui
18 | * @version 1.0.0
19 | * @since 1.0.0
20 | */
21 | @Activate
22 | public class ConsumerSubscribeListener extends InvokerListenerAdapter {
23 | /**
24 | * subscribe interfaces
25 | */
26 | public static final Set<ClassIdBean> SUBSCRIBEDINTERFACES_SET =
27 | new ConcurrentHashSet<ClassIdBean>();
28 |
29 | @Override
30 | public void referred(Invoker<?> invoker) throws RpcException {
31 | Class<?> interfaceClass = invoker.getInterface();
32 | URL url = invoker.getUrl();
33 | String group = url.getParameter(DubboSpringBootStarterConstants.GROUP);
34 | String version = url.getParameter(DubboSpringBootStarterConstants.VERSION);
35 | ClassIdBean classIdBean = new ClassIdBean(interfaceClass, group, version);
36 | SUBSCRIBEDINTERFACES_SET.add(classIdBean);
37 | }
38 |
39 | @Override
40 | public void destroyed(Invoker<?> invoker) {
41 | Class<?> interfaceClass = invoker.getInterface();
42 | URL url = invoker.getUrl();
43 | String group = url.getParameter(DubboSpringBootStarterConstants.GROUP);
44 | String version = url.getParameter(DubboSpringBootStarterConstants.VERSION);
45 | ClassIdBean classIdBean = new ClassIdBean(interfaceClass, group, version);
46 | SUBSCRIBEDINTERFACES_SET.remove(classIdBean);
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/src/main/java/com/alibaba/dubbo/spring/boot/server/DubboServer.java:
--------------------------------------------------------------------------------
1 | package com.alibaba.dubbo.spring.boot.server;
2 |
3 | import org.springframework.beans.factory.DisposableBean;
4 |
5 | /**
6 | * Hold the dubbo server
7 | *
8 | * @author xionghui
9 | * @version 1.0.2
10 | * @since 1.0.2
11 | */
12 | public final class DubboServer implements DisposableBean {
13 | private volatile boolean stopAwait = false;
14 |
15 | private volatile Thread awaitThread = null;
16 |
17 | public void await() {
18 | try {
19 | this.awaitThread = Thread.currentThread();
20 | while (!this.stopAwait) {
21 | try {
22 | Thread.sleep(10000);
23 | } catch (InterruptedException ex) {
24 | // continue and check the flag
25 | }
26 | }
27 | } finally {
28 | this.awaitThread = null;
29 | }
30 | }
31 |
32 | public void stopAwait() {
33 | this.stopAwait = true;
34 | }
35 |
36 | @Override
37 | public void destroy() throws Exception {
38 | this.stopAwait();
39 | Thread t = this.awaitThread;
40 | if (t != null) {
41 | t.interrupt();
42 | try {
43 | t.join(1000);
44 | } catch (InterruptedException e) {
45 | // Ignored
46 | }
47 | }
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/src/main/resources/META-INF/dubbo/com.alibaba.dubbo.rpc.InvokerListener:
--------------------------------------------------------------------------------
1 | dubbosubscribe=com.alibaba.dubbo.spring.boot.listener.ConsumerSubscribeListener
--------------------------------------------------------------------------------
/src/main/resources/META-INF/spring.factories:
--------------------------------------------------------------------------------
1 | org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
2 | com.alibaba.dubbo.spring.boot.DubboAutoConfiguration,\
3 | com.alibaba.dubbo.spring.boot.DubboProviderAutoConfiguration,\
4 | com.alibaba.dubbo.spring.boot.DubboConsumerAutoConfiguration
5 |
6 | org.springframework.context.ApplicationListener=\
7 | com.alibaba.dubbo.spring.boot.context.event.DubboBannerApplicationListener
8 |
--------------------------------------------------------------------------------
/src/main/resources/META-INF/spring.provides:
--------------------------------------------------------------------------------
1 | provides: dubbo-spring-boot-starter
--------------------------------------------------------------------------------
/src/test/java/com/alibaba/dubbo/spring/boot/Mock.java:
--------------------------------------------------------------------------------
1 | package com.alibaba.dubbo.spring.boot;
2 |
3 | public class Mock {
4 |
5 | }
6 |
--------------------------------------------------------------------------------
/src/test/java/com/alibaba/dubbo/spring/boot/testcase/ClassIdBeanTest.java:
--------------------------------------------------------------------------------
1 | package com.alibaba.dubbo.spring.boot.testcase;
2 |
3 | import org.junit.Test;
4 |
5 | import com.alibaba.dubbo.spring.boot.bean.ClassIdBean;
6 |
7 | import junit.framework.TestCase;
8 |
9 | public class ClassIdBeanTest extends TestCase {
10 |
11 | @Test
12 | public void testClassIdBeanNull() throws Exception {
13 | ClassIdBean classIdBean = new ClassIdBean(null, null, null);
14 | ClassIdBean anoClassIdBean = new ClassIdBean(null, null, null);
15 | assert (classIdBean.equals(anoClassIdBean));
16 | System.out.println("testClassIdBeanNull ok!");
17 | }
18 |
19 | @Test
20 | public void testClassIdBeanNotNull() throws Exception {
21 | ClassIdBean classIdBean = new ClassIdBean(null, "test", null);
22 | ClassIdBean anoClassIdBean = new ClassIdBean(null, "test", null);
23 | assert (classIdBean.equals(anoClassIdBean));
24 | System.out.println("testClassIdBeanNotNull ok!");
25 | }
26 | }
27 |
--------------------------------------------------------------------------------