├── .gitignore ├── LICENSE ├── README.md ├── config-client ├── .gitignore ├── README.md ├── pom.xml └── src │ └── main │ ├── java │ └── cn │ │ └── com │ │ └── study │ │ ├── Application.java │ │ └── controller │ │ └── ApplicationController.java │ └── resources │ ├── bootstrap.yml │ └── log4j2.xml ├── config-server ├── .gitignore ├── README.md ├── config-repo │ ├── config-client-dev.yml │ ├── config-client-prod.yml │ ├── config-client-test.yml │ └── config-client.yml ├── pom.xml ├── src.main.java │ └── cn │ │ └── com │ │ └── study │ │ └── Application.java └── src.main.resources │ ├── application.yml │ └── log4j2.xml ├── eureka-server ├── .gitignore ├── README.md ├── pom.xml └── src │ └── main │ ├── java │ └── cn │ │ └── com │ │ └── study │ │ └── Application.java │ └── resources │ ├── application.yml │ └── log4j2.xml ├── feign-consumer ├── .gitignore ├── README.md ├── pom.xml └── src │ └── main │ ├── java │ └── cn │ │ └── com │ │ └── study │ │ ├── Application.java │ │ ├── controller │ │ └── AppController.java │ │ ├── fallback │ │ └── LogicClientHystrix.java │ │ └── service │ │ └── LogicClient.java │ └── resources │ ├── application.yml │ └── log4j2.xml ├── logic-service ├── .gitignore ├── README.md ├── pom.xml └── src │ └── main │ ├── java │ └── cn │ │ └── com │ │ └── study │ │ ├── Application.java │ │ └── controller │ │ └── AppController.java │ └── resources │ ├── application.yml │ └── log4j2.xml ├── pom.xml └── ribbon-consumer ├── .gitignore ├── README.md ├── pom.xml └── src └── main ├── java └── cn │ └── com │ └── study │ ├── Application.java │ ├── config │ ├── RestConfig.java │ └── ServiceRoot.java │ ├── controller │ └── AppController.java │ └── service │ ├── AppService.java │ ├── BaseService.java │ └── impl │ └── AppServiceImpl.java └── resources ├── application.yml └── log4j2.xml /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled class file 2 | *.class 3 | 4 | # Log file 5 | *.log 6 | 7 | # BlueJ files 8 | *.ctxt 9 | 10 | # Mobile Tools for Java (J2ME) 11 | .mtj.tmp/ 12 | 13 | # Package Files # 14 | *.jar 15 | *.war 16 | *.nar 17 | *.ear 18 | *.zip 19 | *.tar.gz 20 | *.rar 21 | 22 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 23 | hs_err_pid* 24 | -------------------------------------------------------------------------------- /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 | #springcloud学习目录说明 2 | 3 | config-server配置中心服务 4 | 5 | eureka-server 服务注册中心 6 | 7 | logic-service 服务提供者 8 | 9 | ribbon-consumer 服务消费者 10 | 11 | feign-consumer 服务消费者 12 | 13 | config-client 配置中心消费者 14 | 15 | -------------------------------------------------------------------------------- /config-client/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | -------------------------------------------------------------------------------- /config-client/README.md: -------------------------------------------------------------------------------- 1 | # springcloud学习 2 | 3 | 配置中心client模块 4 | -------------------------------------------------------------------------------- /config-client/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | cn.com.study 6 | config-client 7 | 1.0.0 8 | jar 9 | 10 | config-client 11 | http://maven.apache.org 12 | 13 | 14 | org.springframework.boot 15 | spring-boot-starter-parent 16 | 1.5.6.RELEASE 17 | 18 | 19 | 20 | 21 | 22 | 23 | org.springframework.cloud 24 | spring-cloud-dependencies 25 | Dalston.RELEASE 26 | pom 27 | import 28 | 29 | 30 | 31 | 32 | 33 | 34 | org.springframework.boot 35 | spring-boot-starter-web 36 | 37 | 38 | org.springframework.boot 39 | spring-boot-starter-logging 40 | 41 | 42 | 43 | 44 | 45 | 46 | org.springframework.cloud 47 | spring-cloud-starter-eureka 48 | 49 | 50 | 51 | org.springframework.cloud 52 | spring-cloud-starter-config 53 | 54 | 55 | org.springframework.boot 56 | spring-boot-starter-logging 57 | 58 | 59 | 60 | 61 | 62 | org.springframework.boot 63 | spring-boot-starter-actuator 64 | 65 | 66 | 67 | org.springframework.boot 68 | spring-boot-starter-log4j2 69 | 70 | 71 | 72 | 73 | 74 | 75 | org.apache.maven.plugins 76 | maven-compiler-plugin 77 | 78 | ${java.version} 79 | ${java.version} 80 | ${project.build.sourceEncoding} 81 | 82 | 83 | 84 | 85 | org.springframework.boot 86 | spring-boot-maven-plugin 87 | 88 | 89 | 90 | -------------------------------------------------------------------------------- /config-client/src/main/java/cn/com/study/Application.java: -------------------------------------------------------------------------------- 1 | package cn.com.study; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import org.springframework.boot.SpringApplication; 6 | import org.springframework.boot.autoconfigure.SpringBootApplication; 7 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient; 8 | 9 | @EnableDiscoveryClient 10 | @SpringBootApplication 11 | public class Application { 12 | 13 | private final static Logger LOG = LoggerFactory.getLogger(Application.class); 14 | 15 | public static void main(String[] args) { 16 | LOG.info("spring cloud config-client application start to boot..."); 17 | 18 | SpringApplication.run(Application.class, args); 19 | 20 | LOG.info("spring cloud config-client application is running..."); 21 | } 22 | } -------------------------------------------------------------------------------- /config-client/src/main/java/cn/com/study/controller/ApplicationController.java: -------------------------------------------------------------------------------- 1 | package cn.com.study.controller; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import org.springframework.beans.factory.annotation.Value; 6 | import org.springframework.cloud.context.config.annotation.RefreshScope; 7 | import org.springframework.web.bind.annotation.RequestMapping; 8 | import org.springframework.web.bind.annotation.RestController; 9 | 10 | @RefreshScope 11 | @RestController 12 | public class ApplicationController { 13 | 14 | private final static Logger LOG = LoggerFactory.getLogger(ApplicationController.class); 15 | 16 | @Value("${from:NONE}") 17 | private String from; 18 | 19 | @RequestMapping(value = "/from") 20 | public String from() { 21 | LOG.info("property from config-server is: {}", from); 22 | 23 | return this.from; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /config-client/src/main/resources/bootstrap.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: config-client 4 | cloud: 5 | config: 6 | profile: dev 7 | 8 | discovery: 9 | enabled: true 10 | serviceId: CONFIG-SERVER 11 | 12 | server: 13 | port: 8081 14 | 15 | # 服务注册中心 16 | eureka: 17 | client: 18 | serviceUrl: 19 | defaultZone: http://localhost:9090/eureka/ -------------------------------------------------------------------------------- /config-client/src/main/resources/log4j2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | springcloud_eureka_server 5 | D:\\appLog\\${LOG_APP} 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /config-server/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | -------------------------------------------------------------------------------- /config-server/README.md: -------------------------------------------------------------------------------- 1 | # springcloud学习 2 | 3 | 配置中心模块 4 | -------------------------------------------------------------------------------- /config-server/config-repo/config-client-dev.yml: -------------------------------------------------------------------------------- 1 | from: git-dev-1.0 -------------------------------------------------------------------------------- /config-server/config-repo/config-client-prod.yml: -------------------------------------------------------------------------------- 1 | from: git-prod-1.0 -------------------------------------------------------------------------------- /config-server/config-repo/config-client-test.yml: -------------------------------------------------------------------------------- 1 | from: git-test-1.0 -------------------------------------------------------------------------------- /config-server/config-repo/config-client.yml: -------------------------------------------------------------------------------- 1 | from: git-default-1.0 -------------------------------------------------------------------------------- /config-server/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | cn.com.study 6 | config-server 7 | 1.0.0 8 | jar 9 | 10 | config-server 11 | http://maven.apache.org 12 | 13 | 14 | org.springframework.boot 15 | spring-boot-starter-parent 16 | 1.5.6.RELEASE 17 | 18 | 19 | 20 | 21 | 22 | 23 | org.springframework.cloud 24 | spring-cloud-dependencies 25 | Dalston.RELEASE 26 | pom 27 | import 28 | 29 | 30 | 31 | 32 | 33 | 34 | org.springframework.cloud 35 | spring-cloud-config-server 36 | 37 | 38 | org.springframework.boot 39 | spring-boot-starter-logging 40 | 41 | 42 | 43 | 44 | 45 | 46 | org.springframework.cloud 47 | spring-cloud-starter-eureka 48 | 49 | 50 | 51 | org.springframework.boot 52 | spring-boot-starter-log4j2 53 | 54 | 55 | 56 | 57 | 58 | 59 | org.apache.maven.plugins 60 | maven-compiler-plugin 61 | 62 | ${java.version} 63 | ${java.version} 64 | ${project.build.sourceEncoding} 65 | 66 | 67 | 68 | 69 | org.springframework.boot 70 | spring-boot-maven-plugin 71 | 72 | 73 | 74 | -------------------------------------------------------------------------------- /config-server/src.main.java/cn/com/study/Application.java: -------------------------------------------------------------------------------- 1 | package cn.com.study; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import org.springframework.boot.SpringApplication; 6 | import org.springframework.boot.autoconfigure.SpringBootApplication; 7 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient; 8 | import org.springframework.cloud.config.server.EnableConfigServer; 9 | 10 | @EnableDiscoveryClient 11 | @EnableConfigServer 12 | @SpringBootApplication 13 | public class Application { 14 | 15 | private final static Logger LOG = LoggerFactory.getLogger(Application.class); 16 | 17 | public static void main(String[] args) { 18 | LOG.info("spring cloud config-server application start to boot..."); 19 | 20 | SpringApplication.run(Application.class, args); 21 | 22 | LOG.info("spring cloud config-server application is running..."); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /config-server/src.main.resources/application.yml: -------------------------------------------------------------------------------- 1 | 2 | server: 3 | port: 8080 4 | 5 | spring: 6 | application: 7 | name: config-server 8 | 9 | # git管理配置 10 | cloud: 11 | config: 12 | server: 13 | git: 14 | # 配置git仓库位置 15 | uri: https://gitee.com/fxrWinters/springcloud/ 16 | # 配置仓库路径下的相对搜索位置,可以配置多个 17 | searchPaths: config-server/config-repo 18 | # 访问git仓库的用户名 19 | username: fxrCross 20 | # 访问git仓库的用户密码 21 | password: fxr123456 22 | 23 | # 服务注册中心 24 | eureka: 25 | client: 26 | serviceUrl: 27 | defaultZone: http://localhost:9090/eureka/ -------------------------------------------------------------------------------- /config-server/src.main.resources/log4j2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | springcloud_config_server 5 | D:\\appLog\\${LOG_APP} 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /eureka-server/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | .classpath 3 | .project 4 | .settings 5 | -------------------------------------------------------------------------------- /eureka-server/README.md: -------------------------------------------------------------------------------- 1 | # springcloud学习 2 | 3 | eureka服务注册中心模块 4 | -------------------------------------------------------------------------------- /eureka-server/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | cn.com.study 6 | eureka-server 7 | 1.0.0 8 | jar 9 | 10 | eureka-server 11 | http://maven.apache.org 12 | 13 | 14 | org.springframework.boot 15 | spring-boot-starter-parent 16 | 1.5.6.RELEASE 17 | 18 | 19 | 20 | 21 | 22 | 23 | org.springframework.cloud 24 | spring-cloud-dependencies 25 | Dalston.RELEASE 26 | pom 27 | import 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | org.springframework.cloud 36 | spring-cloud-starter-eureka-server 37 | 38 | 39 | org.springframework.boot 40 | spring-boot-starter-logging 41 | 42 | 43 | 44 | 45 | 46 | org.springframework.boot 47 | spring-boot-starter-log4j2 48 | 49 | 50 | 51 | 52 | 53 | 54 | org.apache.maven.plugins 55 | maven-compiler-plugin 56 | 57 | ${java.version} 58 | ${java.version} 59 | ${project.build.sourceEncoding} 60 | 61 | 62 | 63 | 64 | org.springframework.boot 65 | spring-boot-maven-plugin 66 | 67 | 68 | 69 | -------------------------------------------------------------------------------- /eureka-server/src/main/java/cn/com/study/Application.java: -------------------------------------------------------------------------------- 1 | package cn.com.study; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import org.springframework.boot.SpringApplication; 6 | import org.springframework.boot.autoconfigure.SpringBootApplication; 7 | import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer; 8 | 9 | @EnableEurekaServer 10 | @SpringBootApplication 11 | public class Application { 12 | 13 | private final static Logger LOG = LoggerFactory.getLogger(Application.class); 14 | 15 | public static void main(String[] args) { 16 | LOG.info("spring cloud eureka-server application start to boot..."); 17 | 18 | SpringApplication.run(Application.class, args); 19 | 20 | LOG.info("spring cloud eureka-server application is running..."); 21 | } 22 | } -------------------------------------------------------------------------------- /eureka-server/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | 2 | server: 3 | port: 9090 4 | 5 | eureka: 6 | client: 7 | register-with-eureka: false 8 | fetch-registry: false 9 | serviceUrl: 10 | defaultZone: http://localhost:${server.port}/eureka/ -------------------------------------------------------------------------------- /eureka-server/src/main/resources/log4j2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | springcloud_eureka_server 5 | D:\\appLog\\${LOG_APP} 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /feign-consumer/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | -------------------------------------------------------------------------------- /feign-consumer/README.md: -------------------------------------------------------------------------------- 1 | # springcloud学习 2 | 3 | feign-consumer 服务消费者 4 | -------------------------------------------------------------------------------- /feign-consumer/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | cn.com.study 6 | feign-consumer 7 | 1.0.0 8 | jar 9 | 10 | feign-consumer 11 | http://maven.apache.org 12 | 13 | 14 | org.springframework.boot 15 | spring-boot-starter-parent 16 | 1.5.6.RELEASE 17 | 18 | 19 | 20 | 21 | 22 | org.springframework.cloud 23 | spring-cloud-dependencies 24 | Dalston.RELEASE 25 | pom 26 | import 27 | 28 | 29 | 30 | 31 | 32 | 33 | org.springframework.boot 34 | spring-boot-starter-web 35 | 36 | 37 | org.springframework.boot 38 | spring-boot-starter-logging 39 | 40 | 41 | 42 | 43 | 44 | org.springframework.boot 45 | spring-boot-starter-log4j2 46 | 47 | 48 | 49 | 50 | org.springframework.cloud 51 | spring-cloud-starter-eureka 52 | 53 | 54 | org.springframework.cloud 55 | spring-cloud-starter-feign 56 | 57 | 58 | 59 | org.springframework.cloud 60 | spring-cloud-starter-hystrix 61 | 62 | 63 | 64 | com.alibaba 65 | fastjson 66 | 1.2.37 67 | 68 | 69 | 70 | 71 | 72 | 73 | org.apache.maven.plugins 74 | maven-compiler-plugin 75 | 76 | ${java.version} 77 | ${java.version} 78 | ${project.build.sourceEncoding} 79 | 80 | 81 | 82 | org.springframework.boot 83 | spring-boot-maven-plugin 84 | 85 | 86 | 87 | -------------------------------------------------------------------------------- /feign-consumer/src/main/java/cn/com/study/Application.java: -------------------------------------------------------------------------------- 1 | package cn.com.study; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import org.springframework.boot.SpringApplication; 6 | import org.springframework.boot.autoconfigure.SpringBootApplication; 7 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient; 8 | import org.springframework.cloud.netflix.feign.EnableFeignClients; 9 | 10 | @EnableFeignClients 11 | @EnableDiscoveryClient 12 | @SpringBootApplication 13 | public class Application { 14 | 15 | private final static Logger LOG = LoggerFactory.getLogger(Application.class); 16 | 17 | public static void main(String[] args) { 18 | LOG.info("spring cloud feign-consumer application start to boot..."); 19 | SpringApplication.run(Application.class, args); 20 | LOG.info("spring cloud feign-consumer application is running..."); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /feign-consumer/src/main/java/cn/com/study/controller/AppController.java: -------------------------------------------------------------------------------- 1 | package cn.com.study.controller; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.web.bind.annotation.RequestMapping; 7 | import org.springframework.web.bind.annotation.RestController; 8 | 9 | import com.alibaba.fastjson.JSONObject; 10 | 11 | import cn.com.study.service.LogicClient; 12 | 13 | @RestController 14 | public class AppController { 15 | 16 | private final static Logger LOG = LoggerFactory.getLogger(AppController.class); 17 | 18 | @Autowired 19 | private LogicClient logicClient; 20 | 21 | @RequestMapping(value = "/caculate") 22 | public JSONObject caculate() { 23 | LOG.info("feign request..."); 24 | 25 | JSONObject json = logicClient.caculate(10, 20); 26 | LOG.info("caculate result is : {}", json); 27 | 28 | return json; 29 | } 30 | } -------------------------------------------------------------------------------- /feign-consumer/src/main/java/cn/com/study/fallback/LogicClientHystrix.java: -------------------------------------------------------------------------------- 1 | package cn.com.study.fallback; 2 | 3 | import org.springframework.stereotype.Component; 4 | import org.springframework.web.bind.annotation.RequestParam; 5 | 6 | import com.alibaba.fastjson.JSONObject; 7 | 8 | import cn.com.study.service.LogicClient; 9 | 10 | @Component 11 | public class LogicClientHystrix implements LogicClient { 12 | 13 | @Override 14 | public JSONObject caculate(@RequestParam(value = "paramA") Integer paramA, 15 | @RequestParam(value = "paramB") Integer paramB) { 16 | return new JSONObject().fluentPut("result", "error"); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /feign-consumer/src/main/java/cn/com/study/service/LogicClient.java: -------------------------------------------------------------------------------- 1 | package cn.com.study.service; 2 | 3 | import org.springframework.cloud.netflix.feign.FeignClient; 4 | import org.springframework.web.bind.annotation.RequestMapping; 5 | import org.springframework.web.bind.annotation.RequestParam; 6 | 7 | import com.alibaba.fastjson.JSONObject; 8 | 9 | import cn.com.study.fallback.LogicClientHystrix; 10 | 11 | @FeignClient(value = "logic-service", fallback = LogicClientHystrix.class) 12 | public interface LogicClient { 13 | 14 | // 配置 15 | @RequestMapping(value = "/caculate") 16 | JSONObject caculate(@RequestParam(value = "paramA") Integer paramA, 17 | @RequestParam(value = "paramB") Integer paramB); 18 | } 19 | -------------------------------------------------------------------------------- /feign-consumer/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | 2 | server: 3 | port: 8091 4 | 5 | spring: 6 | application: 7 | name: feign-consumer 8 | 9 | # 服务注册中心 10 | eureka: 11 | client: 12 | serviceUrl: 13 | defaultZone: http://localhost:9090/eureka/ 14 | 15 | # 开启hystrix支持 16 | feign: 17 | hystrix: 18 | enabled: true 19 | 20 | -------------------------------------------------------------------------------- /feign-consumer/src/main/resources/log4j2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | springcloud_feign_consumer 5 | D:\\appLog\\${LOG_APP} 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /logic-service/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | -------------------------------------------------------------------------------- /logic-service/README.md: -------------------------------------------------------------------------------- 1 | #springboot 2 | -------------------------------------------------------------------------------- /logic-service/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | cn.com.study 6 | logic-service 7 | 1.0.0 8 | jar 9 | 10 | logic-service 11 | http://maven.apache.org 12 | 13 | 14 | org.springframework.boot 15 | spring-boot-starter-parent 16 | 1.5.6.RELEASE 17 | 18 | 19 | 20 | 21 | 22 | org.springframework.cloud 23 | spring-cloud-dependencies 24 | Dalston.RELEASE 25 | pom 26 | import 27 | 28 | 29 | 30 | 31 | 32 | 33 | org.springframework.boot 34 | spring-boot-starter-web 35 | 36 | 37 | org.springframework.boot 38 | spring-boot-starter-logging 39 | 40 | 41 | 42 | 43 | 44 | org.springframework.boot 45 | spring-boot-starter-log4j2 46 | 47 | 48 | 49 | 50 | org.springframework.cloud 51 | spring-cloud-starter-eureka 52 | 53 | 54 | 55 | com.alibaba 56 | fastjson 57 | 1.2.37 58 | 59 | 60 | 61 | 62 | 63 | 64 | org.apache.maven.plugins 65 | maven-compiler-plugin 66 | 67 | ${java.version} 68 | ${java.version} 69 | ${project.build.sourceEncoding} 70 | 71 | 72 | 73 | org.springframework.boot 74 | spring-boot-maven-plugin 75 | 76 | 77 | 78 | -------------------------------------------------------------------------------- /logic-service/src/main/java/cn/com/study/Application.java: -------------------------------------------------------------------------------- 1 | package cn.com.study; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import org.springframework.boot.SpringApplication; 6 | import org.springframework.boot.autoconfigure.SpringBootApplication; 7 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient; 8 | 9 | @EnableDiscoveryClient 10 | @SpringBootApplication 11 | public class Application { 12 | 13 | private final static Logger LOG = LoggerFactory.getLogger(Application.class); 14 | 15 | public static void main(String[] args) { 16 | LOG.info("spring cloud logic-service application start to boot..."); 17 | SpringApplication.run(Application.class, args); 18 | LOG.info("spring cloud logic-service application is running..."); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /logic-service/src/main/java/cn/com/study/controller/AppController.java: -------------------------------------------------------------------------------- 1 | package cn.com.study.controller; 2 | 3 | import javax.servlet.http.HttpServletRequest; 4 | import javax.servlet.http.HttpServletResponse; 5 | 6 | import org.apache.commons.lang.math.NumberUtils; 7 | import org.slf4j.Logger; 8 | import org.slf4j.LoggerFactory; 9 | import org.springframework.beans.factory.annotation.Autowired; 10 | import org.springframework.cloud.client.serviceregistry.Registration; 11 | import org.springframework.web.bind.annotation.RequestMapping; 12 | import org.springframework.web.bind.annotation.RestController; 13 | 14 | import com.alibaba.fastjson.JSONObject; 15 | 16 | @RestController 17 | public class AppController { 18 | 19 | private final static Logger LOG = LoggerFactory.getLogger(AppController.class); 20 | 21 | @Autowired 22 | private Registration registration; 23 | 24 | @RequestMapping(value = "/caculate") 25 | public JSONObject caculate(HttpServletRequest request, HttpServletResponse response) { 26 | 27 | LOG.info("/caculate, service_id: {}", registration.getServiceId()); 28 | 29 | int paramA = NumberUtils.toInt(request.getParameter("paramA")); 30 | int paramB = NumberUtils.toInt(request.getParameter("paramB")); 31 | 32 | JSONObject result = new JSONObject().fluentPut("result", paramA+paramB); 33 | LOG.info("caculate result is : {}", result); 34 | 35 | return result; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /logic-service/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | 2 | server: 3 | port: 9091 4 | 5 | spring: 6 | application: 7 | name: logic-service 8 | 9 | # 服务注册中心 10 | eureka: 11 | client: 12 | serviceUrl: 13 | defaultZone: http://localhost:9090/eureka/ -------------------------------------------------------------------------------- /logic-service/src/main/resources/log4j2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | springcloud_logic_service 5 | D:\\appLog\\${LOG_APP} 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | cn.com.study 6 | spring-cloud 7 | 1.0.0 8 | pom 9 | 10 | spring-cloud 11 | http://maven.apache.org 12 | 13 | 14 | UTF-8 15 | 1.7 16 | 17 | 18 | 19 | 20 | config-server 21 | 22 | config-client 23 | 24 | eureka-server 25 | 26 | logic-service 27 | 28 | ribbon-consumer 29 | 30 | feign-consumer 31 | 32 | -------------------------------------------------------------------------------- /ribbon-consumer/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | -------------------------------------------------------------------------------- /ribbon-consumer/README.md: -------------------------------------------------------------------------------- 1 | # springcloud学习 2 | 3 | ribbon-consumer 服务消费者 4 | -------------------------------------------------------------------------------- /ribbon-consumer/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | cn.com.study 6 | ribbon-consumer 7 | 1.0.0 8 | jar 9 | 10 | ribbon-consumer 11 | http://maven.apache.org 12 | 13 | 14 | org.springframework.boot 15 | spring-boot-starter-parent 16 | 1.5.6.RELEASE 17 | 18 | 19 | 20 | 21 | 22 | org.springframework.cloud 23 | spring-cloud-dependencies 24 | Dalston.RELEASE 25 | pom 26 | import 27 | 28 | 29 | 30 | 31 | 32 | 33 | org.springframework.boot 34 | spring-boot-starter-web 35 | 36 | 37 | org.springframework.boot 38 | spring-boot-starter-logging 39 | 40 | 41 | 42 | 43 | 44 | org.springframework.boot 45 | spring-boot-starter-log4j2 46 | 47 | 48 | 49 | 50 | org.springframework.cloud 51 | spring-cloud-starter-eureka 52 | 53 | 54 | org.springframework.cloud 55 | spring-cloud-starter-ribbon 56 | 57 | 58 | 59 | org.springframework.cloud 60 | spring-cloud-starter-hystrix 61 | 62 | 63 | 64 | com.alibaba 65 | fastjson 66 | 1.2.37 67 | 68 | 69 | 70 | 71 | 72 | 73 | org.apache.maven.plugins 74 | maven-compiler-plugin 75 | 76 | ${java.version} 77 | ${java.version} 78 | ${project.build.sourceEncoding} 79 | 80 | 81 | 82 | org.springframework.boot 83 | spring-boot-maven-plugin 84 | 85 | 86 | 87 | -------------------------------------------------------------------------------- /ribbon-consumer/src/main/java/cn/com/study/Application.java: -------------------------------------------------------------------------------- 1 | package cn.com.study; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import org.springframework.boot.SpringApplication; 6 | import org.springframework.boot.autoconfigure.SpringBootApplication; 7 | import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker; 8 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient; 9 | 10 | @EnableCircuitBreaker 11 | @EnableDiscoveryClient 12 | @SpringBootApplication 13 | public class Application { 14 | 15 | private final static Logger LOG = LoggerFactory.getLogger(Application.class); 16 | 17 | public static void main(String[] args) { 18 | LOG.info("spring cloud ribbon-consumer application start to boot..."); 19 | SpringApplication.run(Application.class, args); 20 | LOG.info("spring cloud ribbon-consumer application is running..."); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /ribbon-consumer/src/main/java/cn/com/study/config/RestConfig.java: -------------------------------------------------------------------------------- 1 | package cn.com.study.config; 2 | 3 | import org.springframework.cloud.client.loadbalancer.LoadBalanced; 4 | import org.springframework.context.annotation.Bean; 5 | import org.springframework.context.annotation.Configuration; 6 | import org.springframework.web.client.RestTemplate; 7 | 8 | @Configuration 9 | public class RestConfig { 10 | 11 | @Bean 12 | @LoadBalanced 13 | public RestTemplate restTemplate() { 14 | return new RestTemplate(); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /ribbon-consumer/src/main/java/cn/com/study/config/ServiceRoot.java: -------------------------------------------------------------------------------- 1 | package cn.com.study.config; 2 | 3 | import org.springframework.boot.context.properties.ConfigurationProperties; 4 | import org.springframework.stereotype.Component; 5 | 6 | @Component 7 | @ConfigurationProperties(prefix="service.root") 8 | public class ServiceRoot { 9 | 10 | private String logic; 11 | 12 | public String getLogic() { 13 | return logic; 14 | } 15 | 16 | public void setLogic(String logic) { 17 | this.logic = logic; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /ribbon-consumer/src/main/java/cn/com/study/controller/AppController.java: -------------------------------------------------------------------------------- 1 | package cn.com.study.controller; 2 | 3 | import javax.servlet.http.HttpServletRequest; 4 | import javax.servlet.http.HttpServletResponse; 5 | 6 | import org.slf4j.Logger; 7 | import org.slf4j.LoggerFactory; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.web.bind.annotation.RequestMapping; 10 | import org.springframework.web.bind.annotation.RestController; 11 | 12 | import com.alibaba.fastjson.JSONObject; 13 | 14 | import cn.com.study.service.AppService; 15 | 16 | @RestController 17 | public class AppController { 18 | 19 | private final static Logger LOG = LoggerFactory.getLogger(AppController.class); 20 | 21 | @Autowired 22 | private AppService appService; 23 | 24 | @RequestMapping(value = "/caculate") 25 | public JSONObject isRunning(HttpServletRequest request, HttpServletResponse response) { 26 | LOG.info("to caculate..."); 27 | return appService.caculate(1, 2); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /ribbon-consumer/src/main/java/cn/com/study/service/AppService.java: -------------------------------------------------------------------------------- 1 | package cn.com.study.service; 2 | 3 | import com.alibaba.fastjson.JSONObject; 4 | 5 | public interface AppService { 6 | 7 | JSONObject caculate(int paramA, int paramB); 8 | 9 | } 10 | -------------------------------------------------------------------------------- /ribbon-consumer/src/main/java/cn/com/study/service/BaseService.java: -------------------------------------------------------------------------------- 1 | package cn.com.study.service; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.web.client.RestTemplate; 7 | 8 | import cn.com.study.config.ServiceRoot; 9 | 10 | public class BaseService { 11 | 12 | @Autowired 13 | protected RestTemplate restTemplate; 14 | 15 | @Autowired 16 | protected ServiceRoot serviceRoot; 17 | 18 | protected final Logger log = LoggerFactory.getLogger(this.getClass()); 19 | } 20 | -------------------------------------------------------------------------------- /ribbon-consumer/src/main/java/cn/com/study/service/impl/AppServiceImpl.java: -------------------------------------------------------------------------------- 1 | package cn.com.study.service.impl; 2 | 3 | import org.springframework.stereotype.Service; 4 | 5 | import com.alibaba.fastjson.JSONObject; 6 | import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand; 7 | 8 | import cn.com.study.service.AppService; 9 | import cn.com.study.service.BaseService; 10 | 11 | @Service 12 | public class AppServiceImpl extends BaseService implements AppService { 13 | 14 | @HystrixCommand(fallbackMethod = "addServiceFallback") 15 | @Override 16 | public JSONObject caculate(int paramA, int paramB) { 17 | log.info("caculate by: {} and {}", paramA, paramB); 18 | 19 | JSONObject result = restTemplate.getForEntity( 20 | serviceRoot.getLogic() + "/caculate?paramA=" + paramA + "¶mB=" + paramB, 21 | JSONObject.class).getBody(); 22 | 23 | log.info("caculate result is : {}", result); 24 | 25 | return result; 26 | } 27 | 28 | public JSONObject addServiceFallback(int paramA, int paramB) { 29 | return new JSONObject().fluentPut("result", "error"); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /ribbon-consumer/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | 2 | server: 3 | port: 8090 4 | 5 | spring: 6 | application: 7 | name: ribbon-consumer 8 | 9 | # 服务注册中心 10 | eureka: 11 | client: 12 | serviceUrl: 13 | defaultZone: http://localhost:9090/eureka/ 14 | 15 | # 服务提供方 16 | service: 17 | root: 18 | logic: http://LOGIC-SERVICE -------------------------------------------------------------------------------- /ribbon-consumer/src/main/resources/log4j2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | springcloud_ribbon_consumer 5 | D:\\appLog\\${LOG_APP} 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | --------------------------------------------------------------------------------