@EnableEurekaServer、@EnableConfigServer、@EnableAdminServer 和@EnableZuulProxy 走进一家酒吧

Posted

技术标签:

【中文标题】@EnableEurekaServer、@EnableConfigServer、@EnableAdminServer 和@EnableZuulProxy 走进一家酒吧【英文标题】:@EnableEurekaServer, @EnableConfigServer, @EnableAdminServer and @EnableZuulProxy walk into a bar 【发布时间】:2019-05-09 19:53:48 【问题描述】:

我在构建将 Zuul、Eureka 服务器、Config 服务器和 Admin 服务器组合在一个独特应用程序中的 Spring Boot + Spring Cloud 应用程序时遇到问题。

如果你已经在想:“到底为什么,这破坏了微服务概念等等。”我完全同意。这个问题是关于实现它的可行性,而不是问它是否是一个好主意,谢谢你的理解。

有人知道如何实现吗? Spring 2.1.0 + Spring Cloud Finchley 或更高版本的一些解决方案会很棒。

代码显然非常简单:

`

@EnableZuulProxy
@EnableAdminServer
@EnableConfigServer
@EnableEurekaServer
@SpringBootApplication
public class Main 

    public static void main(String[] args) 
        SpringApplication.run(Main.class, args);
    


`

pom也很简单:

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.0.RELEASE</version>
        <relativePath/>
    </parent>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>Greenwich.M3</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-zuul</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-config-server</artifactId>
        </dependency>
        <dependency>
            <groupId>de.codecentric</groupId>
            <artifactId>spring-boot-admin-server</artifactId>
            <version>2.1.1</version>
        </dependency>
        <dependency>
            <groupId>de.codecentric</groupId>
            <artifactId>spring-boot-admin-server-ui</artifactId>
            <version>2.1.1</version>
        </dependency>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
            <version>2.9.2</version>
        </dependency>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger-ui</artifactId>
            <version>2.9.2</version>
        </dependency>
    </dependencies>

还有一个简单明了的配置文件:

spring.application.name=question
server.port=8090

eureka.client.service-url.defaultZone=http://localhost:8090/eureka
spring.boot.admin.context-path=/admin
spring.cloud.config.server.prefix=/config

spring.cloud.config.server.git.uri=...
spring.cloud.config.server.git.searchPaths=...

[...]

我得到的最接近的是使用 2.0.6 + Finchley:

2018-12-08 13:20:10.515  INFO 13078 --- [           main] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]
2018-12-08 13:20:10.519  WARN 13078 --- [ost-startStop-1] o.a.c.loader.WebappClassLoaderBase       : The web application [ROOT] appears to have started a thread named [Rxioscheduler-1 (Evictor)] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread:
 sun.misc.Unsafe.park(Native Method)
 java.util.concurrent.locks.LockSupport.parkNanos(LockSupport.java:215)
 java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.awaitNanos(AbstractQueuedSynchronizer.java:2078)
 java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:1093)
 java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:809)
 java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1074)
 java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1134)
 java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
 java.lang.Thread.run(Thread.java:748)
2018-12-08 13:20:10.534  INFO 13078 --- [           main] ConditionEvaluationReportLoggingListener : 

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2018-12-08 13:20:10.536 ERROR 13078 --- [           main] o.s.b.d.LoggingFailureAnalysisReporter   : 

***************************
APPLICATION FAILED TO START
***************************

Description:

An attempt was made to call the method reactor.retry.Retry.retryMax(J)Lreactor/retry/Retry; but it does not exist. Its class, reactor.retry.Retry, is available from the following locations:

    jar:file:/Users/aaa/.m2/repository/io/projectreactor/addons/reactor-extra/3.1.7.RELEASE/reactor-extra-3.1.7.RELEASE.jar!/reactor/retry/Retry.class

It was loaded from the following location:

    file:/Users/aaa/.m2/repository/io/projectreactor/addons/reactor-extra/3.1.7.RELEASE/reactor-extra-3.1.7.RELEASE.jar


Action:

Correct the classpath of your application so that it contains a single, compatible version of reactor.retry.Retry


Process finished with exit code 1

【问题讨论】:

我建议在您的项目上运行 mvn dependencies:tree 以查看 reactor-extra 模块带来了什么。看起来其中一个 Spring 库正在使用该库的不同版本?如果是这种情况,您可能需要调查是否存在使用相同版本 reactor-extra 的库版本并手动声明它们,而不是使用启动模块定义的默认版本 【参考方案1】:

您需要 2.0.4 版的 spring boot admin。您正在使用与您正在使用的其他 Spring 库不兼容的最新版本 (2.1.1)。

【讨论】:

是的,刚刚试过,它正在工作。 Zuul 无法从 Eureka 获取 route.serviceId 的一些后续问题,同时正确使用 route.url,但我相信这是一个不同的故事。非常感谢

以上是关于@EnableEurekaServer、@EnableConfigServer、@EnableAdminServer 和@EnableZuulProxy 走进一家酒吧的主要内容,如果未能解决你的问题,请参考以下文章

:注册中心启动类上的注解EnableEurekaServer

html 来自http://wiki.jikexueyuan.com/project/kendo-ui-development-tutorial/endo-mvvm-data-binding-enab

Eureka 的搭建

FTP服务器vsftpd配置项-主目录限制(chroot_local_userchroot_list_enable)

EurekaServer自动装配及启动流程解析

Spring cloud Eureka