├── .gitignore
├── LICENSE
├── README.md
├── common
├── pom.xml
└── src
│ └── main
│ └── java
│ └── com
│ └── xkcoding
│ ├── dto
│ └── OrderDTO.java
│ └── service
│ └── IOrderService.java
├── config-client
├── .gitignore
├── pom.xml
└── src
│ ├── main
│ ├── java
│ │ └── com
│ │ │ └── xkcoding
│ │ │ └── configclient
│ │ │ ├── ConfigClientApplication.java
│ │ │ └── controller
│ │ │ └── IndexController.java
│ └── resources
│ │ ├── application.yml
│ │ └── bootstrap.yml
│ └── test
│ └── java
│ └── com
│ └── xkcoding
│ └── configclient
│ └── ConfigClientApplicationTests.java
├── config-server
├── .gitignore
├── pom.xml
└── src
│ ├── main
│ ├── java
│ │ └── com
│ │ │ └── xkcoding
│ │ │ └── configserver
│ │ │ └── ConfigServerApplication.java
│ └── resources
│ │ └── application.yml
│ └── test
│ └── java
│ └── com
│ └── xkcoding
│ └── configserver
│ └── ConfigServerApplicationTests.java
├── doc
└── 单体架构向微服务演进.pptx
├── order-service
├── .gitignore
├── pom.xml
└── src
│ ├── main
│ ├── java
│ │ └── com
│ │ │ └── xkcoding
│ │ │ └── orderservice
│ │ │ ├── OrderServiceApplication.java
│ │ │ ├── config
│ │ │ └── ModelMapperConfig.java
│ │ │ ├── controller
│ │ │ ├── IndexController.java
│ │ │ └── OrderController.java
│ │ │ └── model
│ │ │ └── OrderDO.java
│ └── resources
│ │ └── application.yml
│ └── test
│ └── java
│ └── com
│ └── xkcoding
│ └── orderservice
│ └── OrderServiceApplicationTests.java
├── proxy
├── .gitignore
├── pom.xml
└── src
│ ├── main
│ ├── java
│ │ └── com
│ │ │ └── xkcoding
│ │ │ └── proxy
│ │ │ └── ProxyApplication.java
│ └── resources
│ │ └── application.yml
│ └── test
│ └── java
│ └── com
│ └── xkcoding
│ └── proxy
│ └── ProxyApplicationTests.java
├── registry
├── .gitignore
├── pom.xml
└── src
│ ├── main
│ ├── java
│ │ └── com
│ │ │ └── xkcoding
│ │ │ └── registry
│ │ │ └── RegistryApplication.java
│ └── resources
│ │ └── application.yml
│ └── test
│ └── java
│ └── com
│ └── xkcoding
│ └── registry
│ └── RegistryApplicationTests.java
└── user-service
├── .gitignore
├── pom.xml
└── src
├── main
├── java
│ └── com
│ │ └── xkcoding
│ │ └── userservice
│ │ ├── UserServiceApplication.java
│ │ ├── controller
│ │ ├── CustomerController.java
│ │ └── IndexController.java
│ │ ├── feign
│ │ └── OrderClient.java
│ │ └── model
│ │ └── CustomerDO.java
└── resources
│ └── application.yml
└── test
└── java
└── com
└── xkcoding
└── userservice
└── UserServiceApplicationTests.java
/.gitignore:
--------------------------------------------------------------------------------
1 | # Created by .ignore support plugin (hsz.mobi)
2 | ### Example user template template
3 | ### Example user template
4 |
5 | # IntelliJ project files
6 | .idea
7 | *.iml
8 | out
9 | gen### JetBrains template
10 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm
11 | # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
12 |
13 | # User-specific stuff
14 | .idea/**/workspace.xml
15 | .idea/**/tasks.xml
16 | .idea/**/usage.statistics.xml
17 | .idea/**/dictionaries
18 | .idea/**/shelf
19 |
20 | # Sensitive or high-churn files
21 | .idea/**/dataSources/
22 | .idea/**/dataSources.ids
23 | .idea/**/dataSources.local.xml
24 | .idea/**/sqlDataSources.xml
25 | .idea/**/dynamic.xml
26 | .idea/**/uiDesigner.xml
27 | .idea/**/dbnavigator.xml
28 |
29 | # Gradle
30 | .idea/**/gradle.xml
31 | .idea/**/libraries
32 |
33 | # Gradle and Maven with auto-import
34 | # When using Gradle or Maven with auto-import, you should exclude module files,
35 | # since they will be recreated, and may cause churn. Uncomment if using
36 | # auto-import.
37 | # .idea/modules.xml
38 | # .idea/*.iml
39 | # .idea/modules
40 |
41 | # CMake
42 | cmake-build-*/
43 |
44 | # Mongo Explorer plugin
45 | .idea/**/mongoSettings.xml
46 |
47 | # File-based project format
48 | *.iws
49 |
50 | # IntelliJ
51 | out/
52 |
53 | # mpeltonen/sbt-idea plugin
54 | .idea_modules/
55 |
56 | # JIRA plugin
57 | atlassian-ide-plugin.xml
58 |
59 | # Cursive Clojure plugin
60 | .idea/replstate.xml
61 |
62 | # Crashlytics plugin (for Android Studio and IntelliJ)
63 | com_crashlytics_export_strings.xml
64 | crashlytics.properties
65 | crashlytics-build.properties
66 | fabric.properties
67 |
68 | # Editor-based Rest Client
69 | .idea/httpRequests
70 | ### Eclipse template
71 |
72 | .metadata
73 | bin/
74 | tmp/
75 | *.tmp
76 | *.bak
77 | *.swp
78 | *~.nib
79 | local.properties
80 | .settings/
81 | .loadpath
82 | .recommenders
83 |
84 | # External tool builders
85 | .externalToolBuilders/
86 |
87 | # Locally stored "Eclipse launch configurations"
88 | *.launch
89 |
90 | # PyDev specific (Python IDE for Eclipse)
91 | *.pydevproject
92 |
93 | # CDT-specific (C/C++ Development Tooling)
94 | .cproject
95 |
96 | # CDT- autotools
97 | .autotools
98 |
99 | # Java annotation processor (APT)
100 | .factorypath
101 |
102 | # PDT-specific (PHP Development Tools)
103 | .buildpath
104 |
105 | # sbteclipse plugin
106 | .target
107 |
108 | # Tern plugin
109 | .tern-project
110 |
111 | # TeXlipse plugin
112 | .texlipse
113 |
114 | # STS (Spring Tool Suite)
115 | .springBeans
116 |
117 | # Code Recommenders
118 | .recommenders/
119 |
120 | # Annotation Processing
121 | .apt_generated/
122 |
123 | # Scala IDE specific (Scala & Java development for Eclipse)
124 | .cache-main
125 | .scala_dependencies
126 | .worksheet
127 | ### macOS template
128 | # General
129 | .DS_Store
130 | .AppleDouble
131 | .LSOverride
132 |
133 | # Icon must end with two \r
134 | Icon
135 |
136 | # Thumbnails
137 | ._*
138 |
139 | # Files that might appear in the root of a volume
140 | .DocumentRevisions-V100
141 | .fseventsd
142 | .Spotlight-V100
143 | .TemporaryItems
144 | .Trashes
145 | .VolumeIcon.icns
146 | .com.apple.timemachine.donotpresent
147 |
148 | # Directories potentially created on remote AFP share
149 | .AppleDB
150 | .AppleDesktop
151 | Network Trash Folder
152 | Temporary Items
153 | .apdisk
154 | ### Maven template
155 | target/
156 | pom.xml.tag
157 | pom.xml.releaseBackup
158 | pom.xml.versionsBackup
159 | pom.xml.next
160 | release.properties
161 | dependency-reduced-pom.xml
162 | buildNumber.properties
163 | .mvn/timing.properties
164 | .mvn/wrapper/maven-wrapper.jar
165 | ### Java template
166 | # Compiled class file
167 | *.class
168 |
169 | # Log file
170 | *.log
171 |
172 | # BlueJ files
173 | *.ctxt
174 |
175 | # Mobile Tools for Java (J2ME)
176 | .mtj.tmp/
177 |
178 | # Package Files #
179 | *.jar
180 | *.war
181 | *.nar
182 | *.ear
183 | *.zip
184 | *.tar.gz
185 | *.rar
186 |
187 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
188 | hs_err_pid*
189 |
--------------------------------------------------------------------------------
/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 | # Spring cloud 整合 demo 示例
2 |
3 | > 这仅仅是一个简单的整合项目 ☺
4 |
5 | ## 目录结构
6 |
7 | ```bash
8 | .
9 | ├── LICENSE 开源协议
10 | ├── README.md 项目介绍
11 | ├── common 通用部分
12 | ├── config-client config 配置中心 客户端
13 | ├── config-server config 配置中心 服务端
14 | ├── doc 文档/PPT
15 | ├── order-service 订单服务
16 | ├── proxy zuul 网关
17 | ├── registry eureka 注册中心
18 | └── user-service 用户服务
19 | ```
20 |
21 | ## 启动顺序
22 |
23 | 1. 启动注册中心服务
24 | 2. 启动配置中心服务端(配置仓库地址:https://github.com/xkcoding/spring-cloud-learning-simple-demo-config )
25 | 3. 启动用户服务、订单服务、配置中心客户端
26 | 4. 启动zuul网关
27 | 5. enjoy ~
28 |
29 | ## Spring Cloud 资料
30 |
31 | > 聪明的你应该可以自己找到下面的关键词
32 |
33 | 1. 小马哥系列
34 | 2. 占小狼的博客
35 | 3. 程序猿DD
36 | 4. 纯洁的微笑
37 | 5. 方志朋
38 | 6. 芋道源码
39 | 7. 周立
40 |
41 | ## 联系我
42 | - mail: 237497819@qq.com
43 | - QQ: 237497819
--------------------------------------------------------------------------------
/common/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
12 | * 订单 DTO 13 | *
14 | * 15 | * @package: com.xkcoding.dto 16 | * @description: 订单 DTO 17 | * @author: yangkai.shen 18 | * @date: Created in 2018/8/13 下午10:34 19 | * @copyright: Copyright (c) 2018 20 | * @version: V1.0 21 | * @modified: yangkai.shen 22 | */ 23 | @Data 24 | @NoArgsConstructor 25 | @AllArgsConstructor 26 | @Builder 27 | public class OrderDTO { 28 | /** 29 | * 订单id 30 | */ 31 | private Long id; 32 | 33 | /** 34 | * 订单名称 35 | */ 36 | private String name; 37 | 38 | /** 39 | * 订单详情 40 | */ 41 | private String detail; 42 | 43 | /** 44 | * 订单总价 45 | */ 46 | private BigDecimal amount; 47 | } 48 | -------------------------------------------------------------------------------- /common/src/main/java/com/xkcoding/service/IOrderService.java: -------------------------------------------------------------------------------- 1 | package com.xkcoding.service; 2 | 3 | import com.xkcoding.dto.OrderDTO; 4 | 5 | /** 6 | *7 | * 订单 Service 8 | *
9 | * 10 | * @package: com.xkcoding.service 11 | * @description: 订单 Service 12 | * @author: yangkai.shen 13 | * @date: Created in 2018/8/13 下午10:36 14 | * @copyright: Copyright (c) 2018 15 | * @version: V1.0 16 | * @modified: yangkai.shen 17 | */ 18 | public interface IOrderService { 19 | 20 | /** 21 | * 创建订单 22 | * 23 | * @param dto 订单实体 24 | * @return 创建的订单对象 25 | */ 26 | OrderDTO create(OrderDTO dto); 27 | 28 | /** 29 | * 根据订单 id 获取订单对象 30 | * 31 | * @param id 订单id 32 | * @return 订单对象 33 | */ 34 | OrderDTO getMyOrder(Long id); 35 | } 36 | -------------------------------------------------------------------------------- /config-client/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | .sts4-cache 12 | 13 | ### IntelliJ IDEA ### 14 | .idea 15 | *.iws 16 | *.iml 17 | *.ipr 18 | 19 | ### NetBeans ### 20 | /nbproject/private/ 21 | /build/ 22 | /nbbuild/ 23 | /dist/ 24 | /nbdist/ 25 | /.nb-gradle/ -------------------------------------------------------------------------------- /config-client/pom.xml: -------------------------------------------------------------------------------- 1 | 2 |8 | * 配置中心客户端 9 | *
10 | * 11 | * @package: com.xkcoding.configclient 12 | * @description: 配置中心客户端 13 | * @author: yangkai.shen 14 | * @date: Created in 2018/8/14 下午3:02 15 | * @copyright: Copyright (c) 2018 16 | * @version: V1.0 17 | * @modified: yangkai.shen 18 | */ 19 | @SpringBootApplication 20 | public class ConfigClientApplication { 21 | 22 | public static void main(String[] args) { 23 | SpringApplication.run(ConfigClientApplication.class, args); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /config-client/src/main/java/com/xkcoding/configclient/controller/IndexController.java: -------------------------------------------------------------------------------- 1 | package com.xkcoding.configclient.controller; 2 | 3 | import com.google.common.collect.Maps; 4 | import org.springframework.beans.factory.annotation.Value; 5 | import org.springframework.cloud.context.config.annotation.RefreshScope; 6 | import org.springframework.web.bind.annotation.GetMapping; 7 | import org.springframework.web.bind.annotation.RequestMapping; 8 | import org.springframework.web.bind.annotation.RestController; 9 | 10 | import java.util.Map; 11 | 12 | /** 13 | *14 | * 首页 Controller 15 | *
16 | * 17 | * @package: com.xkcoding.configclient.controller 18 | * @description: 首页 Controller 19 | * @author: yangkai.shen 20 | * @date: Created in 2018/8/14 下午2:55 21 | * @copyright: Copyright (c) 2018 22 | * @version: V1.0 23 | * @modified: yangkai.shen 24 | */ 25 | @RestController 26 | @RefreshScope 27 | @RequestMapping("/api") 28 | public class IndexController { 29 | @Value("${demo.name}") 30 | private String name; 31 | 32 | @Value("${demo.version}") 33 | private String version; 34 | 35 | @GetMapping("/info") 36 | public Map9 | * 配置中心服务端 10 | *
11 | * 12 | * @package: com.xkcoding.configserver 13 | * @description: 配置中心服务端 14 | * @author: yangkai.shen 15 | * @date: Created in 2018/8/14 上午12:13 16 | * @copyright: Copyright (c) 2018 17 | * @version: V1.0 18 | * @modified: yangkai.shen 19 | */ 20 | @EnableConfigServer 21 | @SpringBootApplication 22 | public class ConfigServerApplication { 23 | 24 | public static void main(String[] args) { 25 | SpringApplication.run(ConfigServerApplication.class, args); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /config-server/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 9000 3 | spring: 4 | application: 5 | name: config-server 6 | rabbitmq: 7 | host: localhost 8 | port: 5672 9 | username: guest 10 | password: guest 11 | cloud: 12 | bus: 13 | trace: 14 | enabled: true 15 | # 配置中心配置 16 | config: 17 | server: 18 | git: 19 | uri: https://github.com/xkcoding/spring-cloud-learning-simple-demo-config 20 | default-label: master 21 | eureka: 22 | client: 23 | # 配置注册中心地址 24 | service-url: 25 | defaultZone: http://localhost:8761/eureka/ 26 | management: 27 | endpoints: 28 | web: 29 | exposure: 30 | include: bus-refresh -------------------------------------------------------------------------------- /config-server/src/test/java/com/xkcoding/configserver/ConfigServerApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.xkcoding.configserver; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class ConfigServerApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /doc/单体架构向微服务演进.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xkcoding/spring-cloud-learning-simple-demo/80fe93312d075eb92f8464a01228cd6c475b4bec/doc/单体架构向微服务演进.pptx -------------------------------------------------------------------------------- /order-service/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | .sts4-cache 12 | 13 | ### IntelliJ IDEA ### 14 | .idea 15 | *.iws 16 | *.iml 17 | *.ipr 18 | 19 | ### NetBeans ### 20 | /nbproject/private/ 21 | /build/ 22 | /nbbuild/ 23 | /dist/ 24 | /nbdist/ 25 | /.nb-gradle/ -------------------------------------------------------------------------------- /order-service/pom.xml: -------------------------------------------------------------------------------- 1 | 2 |9 | * 订单服务 10 | *
11 | * 12 | * @package: com.xkcoding.orderservice 13 | * @description: 订单服务 14 | * @author: yangkai.shen 15 | * @date: Created in 2018/8/13 下午10:21 16 | * @copyright: Copyright (c) 2018 17 | * @version: V1.0 18 | * @modified: yangkai.shen 19 | */ 20 | @EnableDiscoveryClient 21 | @SpringBootApplication 22 | public class OrderServiceApplication { 23 | 24 | public static void main(String[] args) { 25 | SpringApplication.run(OrderServiceApplication.class, args); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /order-service/src/main/java/com/xkcoding/orderservice/config/ModelMapperConfig.java: -------------------------------------------------------------------------------- 1 | package com.xkcoding.orderservice.config; 2 | 3 | import org.modelmapper.ModelMapper; 4 | import org.springframework.context.annotation.Bean; 5 | import org.springframework.context.annotation.Configuration; 6 | 7 | /** 8 | *9 | * ModelMapper 配置类 10 | *
11 | * 12 | * @package: com.xkcoding.orderservice.config 13 | * @description: ModelMapper 配置类 14 | * @author: yangkai.shen 15 | * @date: Created in 2018/8/13 下午11:03 16 | * @copyright: Copyright (c) 2018 17 | * @version: V1.0 18 | * @modified: yangkai.shen 19 | */ 20 | @Configuration 21 | public class ModelMapperConfig { 22 | @Bean 23 | public ModelMapper modelMapper() { 24 | return new ModelMapper(); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /order-service/src/main/java/com/xkcoding/orderservice/controller/IndexController.java: -------------------------------------------------------------------------------- 1 | package com.xkcoding.orderservice.controller; 2 | 3 | import org.springframework.beans.factory.annotation.Value; 4 | import org.springframework.web.bind.annotation.GetMapping; 5 | import org.springframework.web.bind.annotation.RestController; 6 | 7 | /** 8 | *9 | * 首页 Controller 10 | *
11 | * 12 | * @package: com.xkcoding.orderservice.controller 13 | * @description: 首页 Controller 14 | * @author: yangkai.shen 15 | * @date: Created in 2018/8/13 下午10:23 16 | * @copyright: Copyright (c) 2018 17 | * @version: V1.0 18 | * @modified: yangkai.shen 19 | */ 20 | @RestController 21 | public class IndexController { 22 | 23 | @Value("${spring.application.name}") 24 | private String applicationName; 25 | 26 | @Value("${server.port}") 27 | private String port; 28 | 29 | @GetMapping("/index") 30 | public String index() { 31 | return "欢迎来到:" + applicationName + " 当前端口号为:" + port; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /order-service/src/main/java/com/xkcoding/orderservice/controller/OrderController.java: -------------------------------------------------------------------------------- 1 | package com.xkcoding.orderservice.controller; 2 | 3 | import cn.hutool.core.util.NumberUtil; 4 | import cn.hutool.core.util.RandomUtil; 5 | import com.google.common.collect.Lists; 6 | import com.xkcoding.dto.OrderDTO; 7 | import com.xkcoding.orderservice.model.OrderDO; 8 | import com.xkcoding.service.IOrderService; 9 | import org.modelmapper.ModelMapper; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.web.bind.annotation.*; 12 | 13 | import javax.annotation.PostConstruct; 14 | import java.util.List; 15 | 16 | /** 17 | *18 | * 订单 Controller 19 | *
20 | * 21 | * @package: com.xkcoding.orderservice.controller 22 | * @description: 订单 Controller 23 | * @author: yangkai.shen 24 | * @date: Created in 2018/8/13 下午10:28 25 | * @copyright: Copyright (c) 2018 26 | * @version: V1.0 27 | * @modified: yangkai.shen 28 | */ 29 | @RestController 30 | @RequestMapping("/api/order") 31 | public class OrderController implements IOrderService { 32 | private static final List12 | * 订单实体 13 | *
14 | * 15 | * @package: com.xkcoding.orderservice.model 16 | * @description: 订单实体 17 | * @author: yangkai.shen 18 | * @date: Created in 2018/8/13 下午10:51 19 | * @copyright: Copyright (c) 2018 20 | * @version: V1.0 21 | * @modified: yangkai.shen 22 | */ 23 | @Data 24 | @NoArgsConstructor 25 | @AllArgsConstructor 26 | @Builder 27 | public class OrderDO { 28 | /** 29 | * 订单id 30 | */ 31 | private Long id; 32 | 33 | /** 34 | * 订单名称 35 | */ 36 | private String name; 37 | 38 | /** 39 | * 订单详情 40 | */ 41 | private String detail; 42 | 43 | /** 44 | * 订单总价 45 | */ 46 | private BigDecimal amount; 47 | } 48 | -------------------------------------------------------------------------------- /order-service/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8091 3 | spring: 4 | application: 5 | name: order 6 | eureka: 7 | client: 8 | # 配置注册中心地址 9 | service-url: 10 | defaultZone: http://localhost:8761/eureka/ -------------------------------------------------------------------------------- /order-service/src/test/java/com/xkcoding/orderservice/OrderServiceApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.xkcoding.orderservice; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class OrderServiceApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /proxy/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | .sts4-cache 12 | 13 | ### IntelliJ IDEA ### 14 | .idea 15 | *.iws 16 | *.iml 17 | *.ipr 18 | 19 | ### NetBeans ### 20 | /nbproject/private/ 21 | /build/ 22 | /nbbuild/ 23 | /dist/ 24 | /nbdist/ 25 | /.nb-gradle/ -------------------------------------------------------------------------------- /proxy/pom.xml: -------------------------------------------------------------------------------- 1 | 2 |11 | * Zuul 网关 12 | *
13 | * 14 | * @package: com.xkcoding.proxy 15 | * @description: Zuul 网关 16 | * @author: yangkai.shen 17 | * @date: Created in 2018/8/14 上午12:09 18 | * @copyright: Copyright (c) 2018 19 | * @version: V1.0 20 | * @modified: yangkai.shen 21 | */ 22 | @EnableDiscoveryClient 23 | @EnableZuulProxy 24 | @SpringBootApplication 25 | public class ProxyApplication { 26 | 27 | public static void main(String[] args) { 28 | SpringApplication.run(ProxyApplication.class, args); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /proxy/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8888 3 | spring: 4 | application: 5 | name: proxy 6 | eureka: 7 | client: 8 | # 配置注册中心地址 9 | service-url: 10 | defaultZone: http://localhost:8761/eureka/ 11 | zuul: 12 | routes: 13 | userApi: 14 | path: /user/** 15 | serviceId: user 16 | orderApi: 17 | path: /order/** 18 | serviceId: order 19 | host: 20 | connect-timeout-millis: 60000 21 | socket-timeout-millis: 60000 22 | ribbon: 23 | ReadTimeout: 15000 24 | ConnectTimeout: 15000 25 | hystrix: 26 | command: 27 | default: 28 | execution: 29 | isolation: 30 | thread: 31 | timeoutInMilliseconds: 60000 -------------------------------------------------------------------------------- /proxy/src/test/java/com/xkcoding/proxy/ProxyApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.xkcoding.proxy; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class ProxyApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /registry/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | .sts4-cache 12 | 13 | ### IntelliJ IDEA ### 14 | .idea 15 | *.iws 16 | *.iml 17 | *.ipr 18 | 19 | ### NetBeans ### 20 | /nbproject/private/ 21 | /build/ 22 | /nbbuild/ 23 | /dist/ 24 | /nbdist/ 25 | /.nb-gradle/ -------------------------------------------------------------------------------- /registry/pom.xml: -------------------------------------------------------------------------------- 1 | 2 |9 | * Eureka 注册中心 10 | *
11 | * 12 | * @package: com.xkcoding.registry 13 | * @description: Eureka 注册中心 14 | * @author: yangkai.shen 15 | * @date: Created in 2018/8/13 下午8:28 16 | * @copyright: Copyright (c) 2018 17 | * @version: V1.0 18 | * @modified: yangkai.shen 19 | */ 20 | @EnableEurekaServer 21 | @SpringBootApplication 22 | public class RegistryApplication { 23 | 24 | public static void main(String[] args) { 25 | SpringApplication.run(RegistryApplication.class, args); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /registry/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: registry 4 | server: 5 | port: 8761 6 | eureka: 7 | server: 8 | # 关闭自我保护 9 | enable-self-preservation: false 10 | client: 11 | # 配置注册中心地址 12 | service-url: 13 | defaultZone: http://localhost:${server.port}/eureka/ 14 | # 设置不自我注册 15 | register-with-eureka: false 16 | # 设置不查找注册中心 17 | fetch-registry: false -------------------------------------------------------------------------------- /registry/src/test/java/com/xkcoding/registry/RegistryApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.xkcoding.registry; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class RegistryApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /user-service/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | .sts4-cache 12 | 13 | ### IntelliJ IDEA ### 14 | .idea 15 | *.iws 16 | *.iml 17 | *.ipr 18 | 19 | ### NetBeans ### 20 | /nbproject/private/ 21 | /build/ 22 | /nbbuild/ 23 | /dist/ 24 | /nbdist/ 25 | /.nb-gradle/ -------------------------------------------------------------------------------- /user-service/pom.xml: -------------------------------------------------------------------------------- 1 | 2 |10 | * 用户服务 11 | *
12 | * 13 | * @package: com.xkcoding.userservice 14 | * @description: 用户服务 15 | * @author: yangkai.shen 16 | * @date: Created in 2018/8/13 下午9:54 17 | * @copyright: Copyright (c) 2018 18 | * @version: V1.0 19 | * @modified: yangkai.shen 20 | */ 21 | @EnableDiscoveryClient 22 | @EnableFeignClients 23 | @SpringBootApplication 24 | public class UserServiceApplication { 25 | 26 | public static void main(String[] args) { 27 | SpringApplication.run(UserServiceApplication.class, args); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /user-service/src/main/java/com/xkcoding/userservice/controller/CustomerController.java: -------------------------------------------------------------------------------- 1 | package com.xkcoding.userservice.controller; 2 | 3 | import com.google.common.collect.Lists; 4 | import com.google.common.collect.Maps; 5 | import com.xkcoding.dto.OrderDTO; 6 | import com.xkcoding.userservice.feign.OrderClient; 7 | import com.xkcoding.userservice.model.CustomerDO; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.web.bind.annotation.*; 10 | 11 | import javax.annotation.PostConstruct; 12 | import java.util.List; 13 | import java.util.Map; 14 | 15 | /** 16 | *17 | * 用户 Controller 18 | *
19 | * 20 | * @package: com.xkcoding.userservice.controller 21 | * @description: 用户 Controller 22 | * @author: yangkai.shen 23 | * @date: Created in 2018/8/14 上午10:06 24 | * @copyright: Copyright (c) 2018 25 | * @version: V1.0 26 | * @modified: yangkai.shen 27 | */ 28 | @RestController 29 | @RequestMapping("api/user") 30 | public class CustomerController { 31 | private static final List9 | * 首页 Controller 10 | *
11 | * 12 | * @package: com.xkcoding.orderservice.controller 13 | * @description: 首页 Controller 14 | * @author: yangkai.shen 15 | * @date: Created in 2018/8/13 下午10:23 16 | * @copyright: Copyright (c) 2018 17 | * @version: V1.0 18 | * @modified: yangkai.shen 19 | */ 20 | @RestController 21 | public class IndexController { 22 | 23 | @Value("${spring.application.name}") 24 | private String applicationName; 25 | 26 | @Value("${server.port}") 27 | private String port; 28 | 29 | @GetMapping("/index") 30 | public String index() { 31 | return "欢迎来到:" + applicationName + " 当前端口号为:" + port; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /user-service/src/main/java/com/xkcoding/userservice/feign/OrderClient.java: -------------------------------------------------------------------------------- 1 | package com.xkcoding.userservice.feign; 2 | 3 | import com.xkcoding.dto.OrderDTO; 4 | import com.xkcoding.service.IOrderService; 5 | import org.springframework.cloud.openfeign.FeignClient; 6 | import org.springframework.stereotype.Component; 7 | import org.springframework.web.bind.annotation.GetMapping; 8 | import org.springframework.web.bind.annotation.PathVariable; 9 | import org.springframework.web.bind.annotation.PostMapping; 10 | import org.springframework.web.bind.annotation.RequestBody; 11 | 12 | /** 13 | *14 | * 远程调用 Order 服务 15 | *
16 | * 17 | * @package: com.xkcoding.userservice.feign 18 | * @description: 远程调用 Order 服务 19 | * @author: yangkai.shen 20 | * @date: Created in 2018/8/14 上午10:15 21 | * @copyright: Copyright (c) 2018 22 | * @version: V1.0 23 | * @modified: yangkai.shen 24 | */ 25 | @FeignClient(value = "order", path = "/api/order") 26 | @Component 27 | public interface OrderClient extends IOrderService { 28 | /** 29 | * 创建订单 30 | * 31 | * @param dto 订单实体 32 | * @return 创建的订单对象 33 | */ 34 | @Override 35 | @PostMapping("") 36 | OrderDTO create(@RequestBody OrderDTO dto); 37 | 38 | /** 39 | * 根据订单 id 获取订单对象 40 | * 41 | * @param id 订单id 42 | * @return 订单对象 43 | */ 44 | @Override 45 | @GetMapping("/{id}") 46 | OrderDTO getMyOrder(@PathVariable(name = "id") Long id); 47 | } 48 | -------------------------------------------------------------------------------- /user-service/src/main/java/com/xkcoding/userservice/model/CustomerDO.java: -------------------------------------------------------------------------------- 1 | package com.xkcoding.userservice.model; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Builder; 5 | import lombok.Data; 6 | import lombok.NoArgsConstructor; 7 | 8 | /** 9 | *10 | * 用户 DO 11 | *
12 | * 13 | * @package: com.xkcoding.userservice.model 14 | * @description: 用户 DO 15 | * @author: yangkai.shen 16 | * @date: Created in 2018/8/14 上午10:03 17 | * @copyright: Copyright (c) 2018 18 | * @version: V1.0 19 | * @modified: yangkai.shen 20 | */ 21 | @Data 22 | @NoArgsConstructor 23 | @AllArgsConstructor 24 | @Builder 25 | public class CustomerDO { 26 | /** 27 | * 用户id 28 | */ 29 | private Long id; 30 | 31 | /** 32 | * 用户名 33 | */ 34 | private String username; 35 | 36 | /** 37 | * 用户密码 38 | */ 39 | private String password; 40 | 41 | /** 42 | * 用户角色 43 | */ 44 | private String role; 45 | } 46 | -------------------------------------------------------------------------------- /user-service/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8081 3 | spring: 4 | application: 5 | name: user 6 | eureka: 7 | client: 8 | # 配置注册中心地址 9 | service-url: 10 | defaultZone: http://localhost:8761/eureka/ 11 | ribbon: 12 | ReadTimeout: 60000 13 | ConnectTimeout: 60000 -------------------------------------------------------------------------------- /user-service/src/test/java/com/xkcoding/userservice/UserServiceApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.xkcoding.userservice; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class UserServiceApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | --------------------------------------------------------------------------------