├── .gitignore ├── LICENSE ├── README.md ├── eureka-server ├── .classpath ├── .gitignore ├── .project ├── .settings │ ├── org.eclipse.core.resources.prefs │ ├── org.eclipse.jdt.core.prefs │ └── org.eclipse.m2e.core.prefs ├── logs │ └── eureka-server-info-20181119.log.0 ├── pom.xml └── src │ └── main │ ├── java │ └── cn │ │ └── springcloud │ │ └── nacos │ │ └── EurekaServerApplication.java │ └── resources │ ├── bootstrap.yml │ └── logback.xml ├── pom.xml └── zuul-server ├── pom.xml └── src └── main ├── java └── cn │ └── springcloud │ └── nacos │ ├── NewZuulRouteLocator.java │ ├── ZuulServerApplication.java │ ├── biz │ └── PropertiesAssemble.java │ ├── config │ └── NewZuulConfig.java │ └── entity │ └── ZuulRouteEntity.java └── resources ├── bootstrap.yml └── logback.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 | # spring-cloud-zuul-nacos 2 | zuul集成Nacos实现动态路由 3 | -------------------------------------------------------------------------------- /eureka-server/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 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 | -------------------------------------------------------------------------------- /eureka-server/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | -------------------------------------------------------------------------------- /eureka-server/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | eureka-server 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.eclipse.m2e.core.maven2Builder 15 | 16 | 17 | 18 | 19 | 20 | org.eclipse.jdt.core.javanature 21 | org.eclipse.m2e.core.maven2Nature 22 | 23 | 24 | -------------------------------------------------------------------------------- /eureka-server/.settings/org.eclipse.core.resources.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | encoding//src/main/java=UTF-8 3 | encoding//src/main/resources=UTF-8 4 | encoding/=UTF-8 5 | -------------------------------------------------------------------------------- /eureka-server/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 3 | org.eclipse.jdt.core.compiler.compliance=1.8 4 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning 5 | org.eclipse.jdt.core.compiler.source=1.8 6 | -------------------------------------------------------------------------------- /eureka-server/.settings/org.eclipse.m2e.core.prefs: -------------------------------------------------------------------------------- 1 | activeProfiles= 2 | eclipse.preferences.version=1 3 | resolveWorkspaceProjects=true 4 | version=1 5 | -------------------------------------------------------------------------------- /eureka-server/logs/eureka-server-info-20181119.log.0: -------------------------------------------------------------------------------- 1 | 2018-11-19 23:37:28.383 [main] INFO o.s.c.a.AnnotationConfigApplicationContext 2 | -Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@63a12c68: startup date [Mon Nov 19 23:37:28 CST 2018]; root of context hierarchy 3 | 2018-11-19 23:37:28.706 [main] INFO o.s.b.f.a.AutowiredAnnotationBeanPostProcessor 4 | -JSR-330 'javax.inject.Inject' annotation found and supported for autowiring 5 | 2018-11-19 23:37:28.750 [main] INFO o.s.c.s.PostProcessorRegistrationDelegate$BeanPostProcessorChecker 6 | -Bean 'configurationPropertiesRebinderAutoConfiguration' of type [org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration$$EnhancerBySpringCGLIB$$f5ea36ed] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying) 7 | 2018-11-19 23:37:28.943 [main] INFO c.s.book.EurekaServerApplication 8 | -No active profile set, falling back to default profiles: default 9 | 2018-11-19 23:37:28.955 [main] INFO o.s.b.w.s.c.AnnotationConfigServletWebServerApplicationContext 10 | -Refreshing org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@7e3181aa: startup date [Mon Nov 19 23:37:28 CST 2018]; parent: org.springframework.context.annotation.AnnotationConfigApplicationContext@63a12c68 11 | 2018-11-19 23:37:29.946 [main] INFO o.s.cloud.context.scope.GenericScope 12 | -BeanFactory id=ff7c1b67-0bdc-3dd7-9a14-65dd8f08d793 13 | 2018-11-19 23:37:29.970 [main] INFO o.s.b.f.a.AutowiredAnnotationBeanPostProcessor 14 | -JSR-330 'javax.inject.Inject' annotation found and supported for autowiring 15 | 2018-11-19 23:37:30.085 [main] INFO o.s.c.s.PostProcessorRegistrationDelegate$BeanPostProcessorChecker 16 | -Bean 'org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration' of type [org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration$$EnhancerBySpringCGLIB$$f5ea36ed] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying) 17 | 2018-11-19 23:37:30.503 [main] INFO o.s.b.w.e.tomcat.TomcatWebServer 18 | -Tomcat initialized with port(s): 8888 (http) 19 | 2018-11-19 23:37:30.523 [main] INFO o.a.coyote.http11.Http11NioProtocol 20 | -Initializing ProtocolHandler ["http-nio-8888"] 21 | 2018-11-19 23:37:30.536 [main] INFO o.a.catalina.core.StandardService 22 | -Starting service [Tomcat] 23 | 2018-11-19 23:37:30.538 [main] INFO o.a.catalina.core.StandardEngine 24 | -Starting Servlet Engine: Apache Tomcat/8.5.31 25 | 2018-11-19 23:37:30.549 [localhost-startStop-1] INFO o.a.c.core.AprLifecycleListener 26 | -The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: [C:\Program Files\Java\jre1.8.0_161\bin;C:\windows\Sun\Java\bin;C:\windows\system32;C:\windows;C:/Program Files/Java/jre1.8.0_161/bin/server;C:/Program Files/Java/jre1.8.0_161/bin;C:/Program Files/Java/jre1.8.0_161/lib/amd64;C:\ProgramData\Oracle\Java\javapath;C:\windows\system32;C:\windows;C:\windows\System32\Wbem;C:\windows\System32\WindowsPowerShell\v1.0\;"C:\Program Files\Java\jdk1.8.0_161\bin;C:\Program Files\Java\jdk1.8.0_161\jre\bin";C:\Program Files\MySQL\MySQL Server 5.5\bin;C:\Users\Administrator\AppData\Local\Microsoft\WindowsApps;E:\Microsoft VS Code\bin;D:\eclipse;;.] 27 | 2018-11-19 23:37:30.719 [localhost-startStop-1] INFO o.a.c.c.C.[Tomcat].[localhost].[/] 28 | -Initializing Spring embedded WebApplicationContext 29 | 2018-11-19 23:37:30.720 [localhost-startStop-1] INFO o.s.web.context.ContextLoader 30 | -Root WebApplicationContext: initialization completed in 1765 ms 31 | 2018-11-19 23:37:31.004 [localhost-startStop-1] WARN c.n.c.sources.URLConfigurationSource 32 | -No URLs will be polled as dynamic configuration sources. 33 | 2018-11-19 23:37:31.005 [localhost-startStop-1] INFO c.n.c.sources.URLConfigurationSource 34 | -To enable URLs as dynamic configuration sources, define System property archaius.configurationSource.additionalUrls or make config.properties available on classpath. 35 | 2018-11-19 23:37:31.018 [localhost-startStop-1] INFO c.n.config.DynamicPropertyFactory 36 | -DynamicPropertyFactory is initialized with configuration sources: com.netflix.config.ConcurrentCompositeConfiguration@64941eb3 37 | 2018-11-19 23:37:32.109 [localhost-startStop-1] INFO o.s.b.w.s.FilterRegistrationBean 38 | -Mapping filter: 'characterEncodingFilter' to: [/*] 39 | 2018-11-19 23:37:32.111 [localhost-startStop-1] INFO o.s.b.w.s.FilterRegistrationBean 40 | -Mapping filter: 'hiddenHttpMethodFilter' to: [/*] 41 | 2018-11-19 23:37:32.111 [localhost-startStop-1] INFO o.s.b.w.s.FilterRegistrationBean 42 | -Mapping filter: 'httpPutFormContentFilter' to: [/*] 43 | 2018-11-19 23:37:32.111 [localhost-startStop-1] INFO o.s.b.w.s.FilterRegistrationBean 44 | -Mapping filter: 'requestContextFilter' to: [/*] 45 | 2018-11-19 23:37:32.112 [localhost-startStop-1] INFO o.s.b.w.s.FilterRegistrationBean 46 | -Mapping filter: 'httpTraceFilter' to: [/*] 47 | 2018-11-19 23:37:32.112 [localhost-startStop-1] INFO o.s.b.w.s.FilterRegistrationBean 48 | -Mapping filter: 'webMvcMetricsFilter' to: [/*] 49 | 2018-11-19 23:37:32.112 [localhost-startStop-1] INFO o.s.b.w.s.FilterRegistrationBean 50 | -Mapping filter: 'servletContainer' to urls: [/eureka/*] 51 | 2018-11-19 23:37:32.112 [localhost-startStop-1] INFO o.s.b.w.s.ServletRegistrationBean 52 | -Servlet dispatcherServlet mapped to [/] 53 | 2018-11-19 23:37:32.188 [localhost-startStop-1] INFO c.s.j.s.i.a.WebApplicationImpl 54 | -Initiating Jersey application, version 'Jersey: 1.19.1 03/11/2016 02:08 PM' 55 | 2018-11-19 23:37:32.249 [localhost-startStop-1] INFO c.n.d.p.DiscoveryJerseyProvider 56 | -Using JSON encoding codec LegacyJacksonJson 57 | 2018-11-19 23:37:32.251 [localhost-startStop-1] INFO c.n.d.p.DiscoveryJerseyProvider 58 | -Using JSON decoding codec LegacyJacksonJson 59 | 2018-11-19 23:37:32.387 [localhost-startStop-1] INFO c.n.d.p.DiscoveryJerseyProvider 60 | -Using XML encoding codec XStreamXml 61 | 2018-11-19 23:37:32.387 [localhost-startStop-1] INFO c.n.d.p.DiscoveryJerseyProvider 62 | -Using XML decoding codec XStreamXml 63 | 2018-11-19 23:37:32.672 [main] WARN o.s.c.n.a.ArchaiusAutoConfiguration 64 | -No spring.application.name found, defaulting to 'application' 65 | 2018-11-19 23:37:32.674 [main] WARN c.n.c.sources.URLConfigurationSource 66 | -No URLs will be polled as dynamic configuration sources. 67 | 2018-11-19 23:37:32.674 [main] INFO c.n.c.sources.URLConfigurationSource 68 | -To enable URLs as dynamic configuration sources, define System property archaius.configurationSource.additionalUrls or make config.properties available on classpath. 69 | 2018-11-19 23:37:32.756 [main] INFO o.s.w.s.h.SimpleUrlHandlerMapping 70 | -Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler] 71 | 2018-11-19 23:37:32.968 [main] INFO o.s.w.s.m.m.a.RequestMappingHandlerAdapter 72 | -Looking for @ControllerAdvice: org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@7e3181aa: startup date [Mon Nov 19 23:37:28 CST 2018]; parent: org.springframework.context.annotation.AnnotationConfigApplicationContext@63a12c68 73 | 2018-11-19 23:37:33.054 [main] INFO o.s.w.s.m.m.a.RequestMappingHandlerMapping 74 | -Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity> org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController.error(javax.servlet.http.HttpServletRequest) 75 | 2018-11-19 23:37:33.057 [main] INFO o.s.w.s.m.m.a.RequestMappingHandlerMapping 76 | -Mapped "{[/error],produces=[text/html]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse) 77 | 2018-11-19 23:37:33.062 [main] INFO o.s.w.s.m.m.a.RequestMappingHandlerMapping 78 | -Mapped "{[/],methods=[GET]}" onto public java.lang.String org.springframework.cloud.netflix.eureka.server.EurekaController.status(javax.servlet.http.HttpServletRequest,java.util.Map) 79 | 2018-11-19 23:37:33.062 [main] INFO o.s.w.s.m.m.a.RequestMappingHandlerMapping 80 | -Mapped "{[/lastn],methods=[GET]}" onto public java.lang.String org.springframework.cloud.netflix.eureka.server.EurekaController.lastn(javax.servlet.http.HttpServletRequest,java.util.Map) 81 | 2018-11-19 23:37:33.091 [main] INFO o.s.w.s.h.SimpleUrlHandlerMapping 82 | -Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler] 83 | 2018-11-19 23:37:33.091 [main] INFO o.s.w.s.h.SimpleUrlHandlerMapping 84 | -Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler] 85 | 2018-11-19 23:37:33.483 [main] INFO o.s.u.f.SpringTemplateLoader 86 | -SpringTemplateLoader for FreeMarker: using resource loader [org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@7e3181aa: startup date [Mon Nov 19 23:37:28 CST 2018]; parent: org.springframework.context.annotation.AnnotationConfigApplicationContext@63a12c68] and template loader path [classpath:/templates/] 87 | 2018-11-19 23:37:33.484 [main] INFO o.s.w.s.v.f.FreeMarkerConfigurer 88 | -ClassTemplateLoader for Spring macros added to FreeMarker configuration 89 | 2018-11-19 23:37:33.668 [main] INFO o.s.c.n.eureka.InstanceInfoFactory 90 | -Setting initial instance status as: STARTING 91 | 2018-11-19 23:37:33.703 [main] INFO c.netflix.discovery.DiscoveryClient 92 | -Initializing Eureka in region us-east-1 93 | 2018-11-19 23:37:33.703 [main] INFO c.netflix.discovery.DiscoveryClient 94 | -Client configured to neither register nor query for data. 95 | 2018-11-19 23:37:33.721 [main] INFO c.netflix.discovery.DiscoveryClient 96 | -Discovery Client initialized at timestamp 1542641853714 with initial instances count: 0 97 | 2018-11-19 23:37:33.774 [main] INFO c.n.e.DefaultEurekaServerContext 98 | -Initializing ... 99 | 2018-11-19 23:37:33.777 [main] WARN c.n.eureka.cluster.PeerEurekaNodes 100 | -The replica size seems to be empty. Check the route 53 DNS Registry 101 | 2018-11-19 23:37:33.794 [main] INFO c.n.e.r.AbstractInstanceRegistry 102 | -Finished initializing remote region registries. All known remote regions: [] 103 | 2018-11-19 23:37:33.797 [main] INFO c.n.e.DefaultEurekaServerContext 104 | -Initialized 105 | 2018-11-19 23:37:33.819 [main] INFO o.s.b.a.e.web.EndpointLinksResolver 106 | -Exposing 2 endpoint(s) beneath base path '/actuator' 107 | 2018-11-19 23:37:33.830 [main] INFO o.s.b.a.e.w.s.WebMvcEndpointHandlerMapping 108 | -Mapped "{[/actuator/health],methods=[GET],produces=[application/vnd.spring-boot.actuator.v2+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.web.servlet.AbstractWebMvcEndpointHandlerMapping$OperationHandler.handle(javax.servlet.http.HttpServletRequest,java.util.Map) 109 | 2018-11-19 23:37:33.831 [main] INFO o.s.b.a.e.w.s.WebMvcEndpointHandlerMapping 110 | -Mapped "{[/actuator/info],methods=[GET],produces=[application/vnd.spring-boot.actuator.v2+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.web.servlet.AbstractWebMvcEndpointHandlerMapping$OperationHandler.handle(javax.servlet.http.HttpServletRequest,java.util.Map) 111 | 2018-11-19 23:37:33.832 [main] INFO o.s.b.a.e.w.s.WebMvcEndpointHandlerMapping 112 | -Mapped "{[/actuator],methods=[GET],produces=[application/vnd.spring-boot.actuator.v2+json || application/json]}" onto protected java.util.Map> org.springframework.boot.actuate.endpoint.web.servlet.WebMvcEndpointHandlerMapping.links(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse) 113 | 2018-11-19 23:37:33.878 [main] INFO o.s.j.e.a.AnnotationMBeanExporter 114 | -Registering beans for JMX exposure on startup 115 | 2018-11-19 23:37:33.886 [main] INFO o.s.j.e.a.AnnotationMBeanExporter 116 | -Bean with name 'environmentManager' has been autodetected for JMX exposure 117 | 2018-11-19 23:37:33.888 [main] INFO o.s.j.e.a.AnnotationMBeanExporter 118 | -Bean with name 'configurationPropertiesRebinder' has been autodetected for JMX exposure 119 | 2018-11-19 23:37:33.888 [main] INFO o.s.j.e.a.AnnotationMBeanExporter 120 | -Bean with name 'refreshScope' has been autodetected for JMX exposure 121 | 2018-11-19 23:37:33.892 [main] INFO o.s.j.e.a.AnnotationMBeanExporter 122 | -Located managed bean 'environmentManager': registering with JMX server as MBean [org.springframework.cloud.context.environment:name=environmentManager,type=EnvironmentManager] 123 | 2018-11-19 23:37:33.911 [main] INFO o.s.j.e.a.AnnotationMBeanExporter 124 | -Located managed bean 'refreshScope': registering with JMX server as MBean [org.springframework.cloud.context.scope.refresh:name=refreshScope,type=RefreshScope] 125 | 2018-11-19 23:37:33.923 [main] INFO o.s.j.e.a.AnnotationMBeanExporter 126 | -Located managed bean 'configurationPropertiesRebinder': registering with JMX server as MBean [org.springframework.cloud.context.properties:name=configurationPropertiesRebinder,context=7e3181aa,type=ConfigurationPropertiesRebinder] 127 | 2018-11-19 23:37:33.936 [main] INFO o.s.c.s.DefaultLifecycleProcessor 128 | -Starting beans in phase 0 129 | 2018-11-19 23:37:33.937 [main] INFO o.s.c.n.e.s.EurekaServiceRegistry 130 | -Registering application unknown with eureka with status UP 131 | 2018-11-19 23:37:33.941 [Thread-13] INFO o.s.c.n.e.s.EurekaServerBootstrap 132 | -Setting the eureka configuration.. 133 | 2018-11-19 23:37:33.942 [Thread-13] INFO o.s.c.n.e.s.EurekaServerBootstrap 134 | -Eureka data center value eureka.datacenter is not set, defaulting to default 135 | 2018-11-19 23:37:33.947 [Thread-13] INFO o.s.c.n.e.s.EurekaServerBootstrap 136 | -Eureka environment value eureka.environment is not set, defaulting to test 137 | 2018-11-19 23:37:33.952 [main] INFO o.a.coyote.http11.Http11NioProtocol 138 | -Starting ProtocolHandler ["http-nio-8888"] 139 | 2018-11-19 23:37:33.967 [Thread-13] INFO o.s.c.n.e.s.EurekaServerBootstrap 140 | -isAws returned false 141 | 2018-11-19 23:37:33.968 [Thread-13] INFO o.s.c.n.e.s.EurekaServerBootstrap 142 | -Initialized server context 143 | 2018-11-19 23:37:33.968 [Thread-13] INFO c.n.e.r.PeerAwareInstanceRegistryImpl 144 | -Got 1 instances from neighboring DS node 145 | 2018-11-19 23:37:33.968 [Thread-13] INFO c.n.e.r.PeerAwareInstanceRegistryImpl 146 | -Renew threshold is: 1 147 | 2018-11-19 23:37:33.968 [Thread-13] INFO c.n.e.r.PeerAwareInstanceRegistryImpl 148 | -Changing status to UP 149 | 2018-11-19 23:37:33.976 [main] INFO o.a.tomcat.util.net.NioSelectorPool 150 | -Using a shared selector for servlet write/read 151 | 2018-11-19 23:37:33.976 [Thread-13] INFO o.s.c.n.e.s.EurekaServerInitializerConfiguration 152 | -Started Eureka Server 153 | 2018-11-19 23:37:33.995 [main] INFO o.s.b.w.e.tomcat.TomcatWebServer 154 | -Tomcat started on port(s): 8888 (http) with context path '' 155 | 2018-11-19 23:37:33.996 [main] INFO o.s.c.n.e.s.EurekaAutoServiceRegistration 156 | -Updating port to 8888 157 | 2018-11-19 23:37:33.998 [main] INFO c.s.book.EurekaServerApplication 158 | -Started EurekaServerApplication in 6.247 seconds (JVM running for 6.861) 159 | 2018-11-19 23:38:18.371 [http-nio-8888-exec-2] INFO o.a.c.c.C.[Tomcat].[localhost].[/] 160 | -Initializing Spring FrameworkServlet 'dispatcherServlet' 161 | 2018-11-19 23:38:18.371 [http-nio-8888-exec-2] INFO o.s.web.servlet.DispatcherServlet 162 | -FrameworkServlet 'dispatcherServlet': initialization started 163 | 2018-11-19 23:38:18.403 [http-nio-8888-exec-2] INFO o.s.web.servlet.DispatcherServlet 164 | -FrameworkServlet 'dispatcherServlet': initialization completed in 32 ms 165 | 2018-11-19 23:38:18.787 [http-nio-8888-exec-1] INFO c.n.e.r.AbstractInstanceRegistry 166 | -Registered instance ZUUL-SERVER/Ricki:zuul-server:5555 with status UP (replication=false) 167 | 2018-11-19 23:38:33.970 [Eureka-EvictionTimer] INFO c.n.e.r.AbstractInstanceRegistry 168 | -Running the evict task with compensationTime 0ms 169 | 2018-11-19 23:39:33.971 [Eureka-EvictionTimer] INFO c.n.e.r.AbstractInstanceRegistry 170 | -Running the evict task with compensationTime 0ms 171 | 2018-11-19 23:40:33.971 [Eureka-EvictionTimer] INFO c.n.e.r.AbstractInstanceRegistry 172 | -Running the evict task with compensationTime 0ms 173 | 2018-11-19 23:41:33.971 [Eureka-EvictionTimer] INFO c.n.e.r.AbstractInstanceRegistry 174 | -Running the evict task with compensationTime 0ms 175 | 2018-11-19 23:42:33.972 [Eureka-EvictionTimer] INFO c.n.e.r.AbstractInstanceRegistry 176 | -Running the evict task with compensationTime 0ms 177 | 2018-11-19 23:43:33.972 [Eureka-EvictionTimer] INFO c.n.e.r.AbstractInstanceRegistry 178 | -Running the evict task with compensationTime 0ms 179 | 2018-11-19 23:44:33.972 [Eureka-EvictionTimer] INFO c.n.e.r.AbstractInstanceRegistry 180 | -Running the evict task with compensationTime 0ms 181 | 2018-11-19 23:45:33.973 [Eureka-EvictionTimer] INFO c.n.e.r.AbstractInstanceRegistry 182 | -Running the evict task with compensationTime 0ms 183 | 2018-11-19 23:46:33.974 [Eureka-EvictionTimer] INFO c.n.e.r.AbstractInstanceRegistry 184 | -Running the evict task with compensationTime 0ms 185 | 2018-11-19 23:47:33.779 [Eureka-PeerNodesUpdater] WARN c.n.eureka.cluster.PeerEurekaNodes 186 | -The replica size seems to be empty. Check the route 53 DNS Registry 187 | 2018-11-19 23:47:33.974 [Eureka-EvictionTimer] INFO c.n.e.r.AbstractInstanceRegistry 188 | -Running the evict task with compensationTime 0ms 189 | 2018-11-19 23:48:33.974 [Eureka-EvictionTimer] INFO c.n.e.r.AbstractInstanceRegistry 190 | -Running the evict task with compensationTime 0ms 191 | 2018-11-19 23:49:33.974 [Eureka-EvictionTimer] INFO c.n.e.r.AbstractInstanceRegistry 192 | -Running the evict task with compensationTime 0ms 193 | 2018-11-19 23:50:33.974 [Eureka-EvictionTimer] INFO c.n.e.r.AbstractInstanceRegistry 194 | -Running the evict task with compensationTime 0ms 195 | 2018-11-19 23:51:33.974 [Eureka-EvictionTimer] INFO c.n.e.r.AbstractInstanceRegistry 196 | -Running the evict task with compensationTime 0ms 197 | 2018-11-19 23:52:33.794 [ReplicaAwareInstanceRegistry - RenewalThresholdUpdater] INFO c.n.e.r.PeerAwareInstanceRegistryImpl 198 | -Current renewal threshold is : 3 199 | 2018-11-19 23:52:33.975 [Eureka-EvictionTimer] INFO c.n.e.r.AbstractInstanceRegistry 200 | -Running the evict task with compensationTime 0ms 201 | 2018-11-19 23:53:33.976 [Eureka-EvictionTimer] INFO c.n.e.r.AbstractInstanceRegistry 202 | -Running the evict task with compensationTime 0ms 203 | 2018-11-19 23:54:33.977 [Eureka-EvictionTimer] INFO c.n.e.r.AbstractInstanceRegistry 204 | -Running the evict task with compensationTime 1ms 205 | 2018-11-19 23:55:33.977 [Eureka-EvictionTimer] INFO c.n.e.r.AbstractInstanceRegistry 206 | -Running the evict task with compensationTime 0ms 207 | 2018-11-19 23:56:33.978 [Eureka-EvictionTimer] INFO c.n.e.r.AbstractInstanceRegistry 208 | -Running the evict task with compensationTime 0ms 209 | 2018-11-19 23:57:33.782 [Eureka-PeerNodesUpdater] WARN c.n.eureka.cluster.PeerEurekaNodes 210 | -The replica size seems to be empty. Check the route 53 DNS Registry 211 | 2018-11-19 23:57:33.978 [Eureka-EvictionTimer] INFO c.n.e.r.AbstractInstanceRegistry 212 | -Running the evict task with compensationTime 0ms 213 | 2018-11-19 23:58:33.979 [Eureka-EvictionTimer] INFO c.n.e.r.AbstractInstanceRegistry 214 | -Running the evict task with compensationTime 0ms 215 | 2018-11-19 23:59:33.982 [Eureka-EvictionTimer] INFO c.n.e.r.AbstractInstanceRegistry 216 | -Running the evict task with compensationTime 2ms 217 | -------------------------------------------------------------------------------- /eureka-server/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | cn.springcloud.nacos 6 | spring-cloud-zuul-nacos 7 | 0.0.1-SNAPSHOT 8 | 9 | eureka-server 10 | 11 | 12 | UTF-8 13 | 1.8 14 | 15 | 16 | 17 | 18 | org.springframework.cloud 19 | spring-cloud-starter-netflix-eureka-server 20 | 21 | 22 | 23 | 24 | 25 | 26 | org.springframework.boot 27 | spring-boot-maven-plugin 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /eureka-server/src/main/java/cn/springcloud/nacos/EurekaServerApplication.java: -------------------------------------------------------------------------------- 1 | package cn.springcloud.nacos; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer; 6 | 7 | @SpringBootApplication 8 | @EnableEurekaServer 9 | public class EurekaServerApplication { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(EurekaServerApplication.class, args); 13 | } 14 | } -------------------------------------------------------------------------------- /eureka-server/src/main/resources/bootstrap.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8888 3 | eureka: 4 | instance: 5 | hostname: localhost 6 | client: 7 | registerWithEureka: false 8 | fetchRegistry: false 9 | serviceUrl: 10 | defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/ -------------------------------------------------------------------------------- /eureka-server/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 15 | ${LOG_HOME}/${LOG_PREFIX}-info.log 16 | 18 | 19 | ${LOG_HOME}/${LOG_PREFIX}-info-%d{yyyyMMdd}.log.%i 20 | 21 | 22 | 100MB 23 | 30 24 | 20GB 25 | 26 | 27 | 28 | %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} 29 | -%msg%n 30 | 31 | 32 | 33 | 34 | 36 | 37 | ERROR 38 | 39 | ${LOG_HOME}/${LOG_PREFIX}-error.log 40 | 42 | 43 | ${LOG_HOME}/${LOG_PREFIX}-error-%d{yyyyMMdd}.log.%i 44 | 45 | 46 | 100MB 47 | 30 48 | 20GB 49 | 50 | 51 | 52 | %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} 53 | -%msg%n 54 | 55 | 56 | 57 | 58 | 59 | 60 | %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - 61 | %msg%n 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | cn.springcloud.nacos 5 | spring-cloud-zuul-nacos 6 | 0.0.1-SNAPSHOT 7 | pom 8 | 9 | 10 | eureka-server 11 | zuul-server 12 | client-a 13 | 14 | 15 | 16 | org.springframework.boot 17 | spring-boot-starter-parent 18 | 2.0.3.RELEASE 19 | 20 | 21 | 22 | 23 | 24 | org.springframework.boot 25 | spring-boot-starter-actuator 26 | 27 | 28 | 29 | org.springframework.boot 30 | spring-boot-starter-web 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | org.springframework.cloud 39 | spring-cloud-dependencies 40 | Finchley.RELEASE 41 | pom 42 | import 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | spring-milestones 51 | Spring Milestones 52 | https://repo.spring.io/libs-milestone 53 | 54 | false 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | org.springframework.boot 63 | spring-boot-maven-plugin 64 | 65 | 66 | 67 | -------------------------------------------------------------------------------- /zuul-server/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | cn.springcloud.nacos 6 | spring-cloud-zuul-nacos 7 | 0.0.1-SNAPSHOT 8 | 9 | zuul-server 10 | 11 | 12 | UTF-8 13 | 1.8 14 | 15 | 16 | 17 | 18 | org.springframework.cloud 19 | spring-cloud-starter-netflix-zuul 20 | 21 | 22 | org.springframework.cloud 23 | spring-cloud-starter-netflix-eureka-client 24 | 25 | 26 | com.alibaba 27 | fastjson 28 | 1.2.47 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | com.alibaba.nacos 37 | nacos-client 38 | 0.4.0 39 | 40 | 41 | 42 | 43 | 44 | 45 | org.springframework.boot 46 | spring-boot-maven-plugin 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /zuul-server/src/main/java/cn/springcloud/nacos/NewZuulRouteLocator.java: -------------------------------------------------------------------------------- 1 | package cn.springcloud.nacos; 2 | 3 | import java.util.LinkedHashMap; 4 | import java.util.Map; 5 | 6 | import cn.springcloud.nacos.biz.PropertiesAssemble; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.cloud.netflix.zuul.filters.RefreshableRouteLocator; 9 | import org.springframework.cloud.netflix.zuul.filters.SimpleRouteLocator; 10 | import org.springframework.cloud.netflix.zuul.filters.ZuulProperties; 11 | import org.springframework.cloud.netflix.zuul.filters.ZuulProperties.ZuulRoute; 12 | import org.springframework.util.StringUtils; 13 | 14 | public class NewZuulRouteLocator extends SimpleRouteLocator implements RefreshableRouteLocator { 15 | 16 | @Autowired 17 | private ZuulProperties properties; 18 | 19 | @Autowired 20 | private PropertiesAssemble propertiesAssemble; 21 | 22 | public NewZuulRouteLocator(String servletPath, ZuulProperties properties) { 23 | super(servletPath, properties); 24 | this.properties = properties; 25 | } 26 | 27 | @Override 28 | public void refresh() { 29 | doRefresh(); 30 | } 31 | 32 | @Override 33 | protected Map locateRoutes() { 34 | LinkedHashMap routesMap = new LinkedHashMap(); 35 | // 从application.properties中加载路由信息 36 | routesMap.putAll(super.locateRoutes()); 37 | // 从Nacos中加载路由信息 38 | routesMap.putAll(propertiesAssemble.getProperties()); 39 | // 优化一下配置 40 | LinkedHashMap values = new LinkedHashMap<>(); 41 | for (Map.Entry entry : routesMap.entrySet()) { 42 | String path = entry.getKey(); 43 | // Prepend with slash if not already present. 44 | if (!path.startsWith("/")) { 45 | path = "/" + path; 46 | } 47 | if (StringUtils.hasText(this.properties.getPrefix())) { 48 | path = this.properties.getPrefix() + path; 49 | if (!path.startsWith("/")) { 50 | path = "/" + path; 51 | } 52 | } 53 | values.put(path, entry.getValue()); 54 | } 55 | return values; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /zuul-server/src/main/java/cn/springcloud/nacos/ZuulServerApplication.java: -------------------------------------------------------------------------------- 1 | package cn.springcloud.nacos; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient; 6 | import org.springframework.cloud.netflix.zuul.EnableZuulProxy; 7 | 8 | @SpringBootApplication 9 | @EnableDiscoveryClient 10 | @EnableZuulProxy 11 | public class ZuulServerApplication { 12 | 13 | public static void main(String[] args) { 14 | SpringApplication.run(ZuulServerApplication.class, args); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /zuul-server/src/main/java/cn/springcloud/nacos/biz/PropertiesAssemble.java: -------------------------------------------------------------------------------- 1 | package cn.springcloud.nacos.biz; 2 | 3 | import java.util.*; 4 | 5 | import com.alibaba.fastjson.JSONObject; 6 | import com.alibaba.nacos.api.NacosFactory; 7 | import com.alibaba.nacos.api.PropertyKeyConst; 8 | import com.alibaba.nacos.api.config.ConfigService; 9 | import com.alibaba.nacos.api.exception.NacosException; 10 | import org.apache.commons.lang.StringUtils; 11 | import org.springframework.beans.BeanUtils; 12 | import org.springframework.cloud.netflix.zuul.filters.ZuulProperties.ZuulRoute; 13 | import org.springframework.stereotype.Component; 14 | 15 | import cn.springcloud.nacos.entity.ZuulRouteEntity; 16 | 17 | @Component 18 | public class PropertiesAssemble{ 19 | 20 | public Map getProperties() { 21 | Map routes = new LinkedHashMap<>(); 22 | List results = listenerNacos("zuul-server","zuul_route"); 23 | for (ZuulRouteEntity result : results) { 24 | if (StringUtils.isBlank(result.getPath()) 25 | /*|| org.apache.commons.lang3.StringUtils.isBlank(result.getUrl())*/) { 26 | continue; 27 | } 28 | ZuulRoute zuulRoute = new ZuulRoute(); 29 | try { 30 | BeanUtils.copyProperties(result, zuulRoute); 31 | } catch (Exception e) { 32 | } 33 | routes.put(zuulRoute.getPath(), zuulRoute); 34 | } 35 | return routes; 36 | } 37 | 38 | private List listenerNacos (String dataId, String group) { 39 | try { 40 | Properties properties = new Properties(); 41 | properties.put(PropertyKeyConst.SERVER_ADDR, "localhost:8848"); 42 | ConfigService configService = NacosFactory.createConfigService(properties); 43 | String content = configService.getConfig(dataId, group, 5000); 44 | System.out.println("从Nacos返回的配置:" + content); 45 | //注册Nacos配置更新监听器 46 | // configService.addListener(dataId, group, new Listener() { 47 | // @Override 48 | // public void receiveConfigInfo(String configInfo) { 49 | // System.out.println("Nacos更新了!"); 50 | // 51 | // } 52 | // @Override 53 | // public Executor getExecutor() { 54 | // return null; 55 | // } 56 | // }); 57 | return JSONObject.parseArray(content, ZuulRouteEntity.class); 58 | } catch (NacosException e) { 59 | e.printStackTrace(); 60 | } 61 | return new ArrayList<>(); 62 | } 63 | } -------------------------------------------------------------------------------- /zuul-server/src/main/java/cn/springcloud/nacos/config/NewZuulConfig.java: -------------------------------------------------------------------------------- 1 | package cn.springcloud.nacos.config; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.boot.autoconfigure.web.ServerProperties; 5 | import org.springframework.cloud.netflix.zuul.filters.ZuulProperties; 6 | import org.springframework.context.annotation.Bean; 7 | import org.springframework.context.annotation.Configuration; 8 | 9 | import cn.springcloud.nacos.NewZuulRouteLocator; 10 | 11 | @Configuration 12 | public class NewZuulConfig { 13 | 14 | @Autowired 15 | private ZuulProperties zuulProperties; 16 | 17 | @Autowired 18 | private ServerProperties serverProperties; 19 | 20 | @Bean 21 | public NewZuulRouteLocator routeLocator() { 22 | NewZuulRouteLocator routeLocator = new NewZuulRouteLocator( 23 | this.serverProperties.getServlet().getServletPrefix(), this.zuulProperties); 24 | return routeLocator; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /zuul-server/src/main/java/cn/springcloud/nacos/entity/ZuulRouteEntity.java: -------------------------------------------------------------------------------- 1 | package cn.springcloud.nacos.entity; 2 | 3 | public class ZuulRouteEntity { 4 | /** 5 | * The ID of the route (the same as its map key by default). 6 | */ 7 | private String id; 8 | /** 9 | * The path (pattern) for the route, e.g. /foo/**. 10 | */ 11 | private String path; 12 | /** 13 | * The service ID (if any) to map to this route. You can specify a 14 | * physical URL or a service, but not both. 15 | */ 16 | private String serviceId; 17 | /** 18 | * A full physical URL to map to the route. An alternative is to use a 19 | * service ID and service discovery to find the physical address. 20 | */ 21 | private String url; 22 | /** 23 | * Flag to determine whether the prefix for this route (the path, minus 24 | * pattern patcher) should be stripped before forwarding. 25 | */ 26 | private boolean stripPrefix = true; 27 | /** 28 | * Flag to indicate that this route should be retryable (if supported). 29 | * Generally retry requires a service ID and ribbon. 30 | */ 31 | private Boolean retryable; 32 | 33 | private String apiName; 34 | 35 | private Boolean enabled; 36 | 37 | public String getId() { 38 | return id; 39 | } 40 | 41 | public void setId(String id) { 42 | this.id = id; 43 | } 44 | 45 | public String getPath() { 46 | return path; 47 | } 48 | 49 | public void setPath(String path) { 50 | this.path = path; 51 | } 52 | 53 | public String getServiceId() { 54 | return serviceId; 55 | } 56 | 57 | public void setServiceId(String serviceId) { 58 | this.serviceId = serviceId; 59 | } 60 | 61 | public String getUrl() { 62 | return url; 63 | } 64 | 65 | public void setUrl(String url) { 66 | this.url = url; 67 | } 68 | 69 | public boolean isStripPrefix() { 70 | return stripPrefix; 71 | } 72 | 73 | public void setStripPrefix(boolean stripPrefix) { 74 | this.stripPrefix = stripPrefix; 75 | } 76 | 77 | public Boolean getRetryable() { 78 | return retryable; 79 | } 80 | 81 | public void setRetryable(Boolean retryable) { 82 | this.retryable = retryable; 83 | } 84 | 85 | public String getApiName() { 86 | return apiName; 87 | } 88 | 89 | public void setApiName(String apiName) { 90 | this.apiName = apiName; 91 | } 92 | 93 | public Boolean getEnabled() { 94 | return enabled; 95 | } 96 | 97 | public void setEnabled(Boolean enabled) { 98 | this.enabled = enabled; 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /zuul-server/src/main/resources/bootstrap.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | # cloud: 3 | # nacos: 4 | # discovery: 5 | # server-addr: localhost:8848 6 | application: 7 | name: zuul-server 8 | server: 9 | port: 5555 10 | eureka: 11 | client: 12 | serviceUrl: 13 | defaultZone: http://${eureka.host:127.0.0.1}:${eureka.port:8888}/eureka/ 14 | instance: 15 | prefer-ip-address: true 16 | ribbon: 17 | eureka: 18 | enabled: false 19 | -------------------------------------------------------------------------------- /zuul-server/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 15 | ${LOG_HOME}/${LOG_PREFIX}-info.log 16 | 18 | 19 | ${LOG_HOME}/${LOG_PREFIX}-info-%d{yyyyMMdd}.log.%i 20 | 21 | 22 | 100MB 23 | 30 24 | 20GB 25 | 26 | 27 | 28 | %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} 29 | -%msg%n 30 | 31 | 32 | 33 | 34 | 36 | 37 | ERROR 38 | 39 | ${LOG_HOME}/${LOG_PREFIX}-error.log 40 | 42 | 43 | ${LOG_HOME}/${LOG_PREFIX}-error-%d{yyyyMMdd}.log.%i 44 | 45 | 46 | 100MB 47 | 30 48 | 20GB 49 | 50 | 51 | 52 | %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} 53 | -%msg%n 54 | 55 | 56 | 57 | 58 | 59 | 60 | %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - 61 | %msg%n 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | --------------------------------------------------------------------------------