springBoot整合Eureka启动失败的解决方案

其实springBoot 整合Eureka 是比较简单 ,可是我发现很多人整合后会启动不了,我这里列出比较常见的报错的原因

报:A child container failed during start

如图下这样

这个原因是因为pom.xml 没有添加

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

假如添加后依然报错:

报错原因是因为Springboot 与 SpringCloud 版本不配对

修改后就行正常运行了!最后把他们相对应的版本贴出来,可以看着相对应的springboot版本改springCloud

Spring Boot Spring Cloud
1.2.x Angel版本
1.3.x Brixton版本
1.4.x stripes Camden版本
1.5.x Dalston版本、Edgware版本
2.0.x Finchley版本

SpringCloud异常(Euruka)

Application run failed java.lang.NoSuchMethodError: org.springframework.boot.builder.SpringApplicationBuilder

在测试Euruka作为服务注册中心的时候碰到了这个问题,错误提示如下:

"C:\Program Files\Java\jdk1.8.0_161\bin\java" -XX:TieredStopAtLevel=1 -........ com.fangxing.springcloud.eurukaserver.EurukaServerApplication
15:04:35.690 [main] DEBUG org.springframework.boot.context.logging.ClasspathLoggingApplicationListener - Application failed to start with classpath: ....... file:/D:/Program%20Files/JetBrains/IntelliJ%20IDEA%202017.3.5/lib/idea_rt.jar]
15:04:35.867 [background-preinit] DEBUG org.jboss.logging - Logging Provider: org.jboss.logging.Log4j2LoggerProvider
15:04:35.869 [background-preinit] INFO org.hibernate.validator.internal.util.Version - HV000001: Hibernate Validator 6.0.7.Final
15:04:35.884 [background-preinit] DEBUG org.hibernate.validator.internal.engine.resolver.TraversableResolvers - Cannot find javax.persistence.Persistence on classpath. Assuming non JPA 2 environment. All properties will per default be traversable.
15:04:35.890 [background-preinit] DEBUG org.hibernate.validator.internal.xml.ValidationXmlParser - Trying to load META-INF/validation.xml for XML based Validator configuration.
15:04:35.892 [background-preinit] DEBUG org.hibernate.validator.internal.xml.ResourceLoaderHelper - Trying to load META-INF/validation.xml via TCCL
15:04:35.893 [background-preinit] DEBUG org.hibernate.validator.internal.xml.ResourceLoaderHelper - Trying to load META-INF/validation.xml via Hibernate Validator's class loader
15:04:35.894 [background-preinit] DEBUG org.hibernate.validator.internal.xml.ValidationXmlParser - No META-INF/validation.xml found. Using annotation based configuration only.
15:04:36.086 [background-preinit] DEBUG org.hibernate.validator.messageinterpolation.ResourceBundleMessageInterpolator - Loaded expression factory via original TCCL
15:04:36.090 [background-preinit] DEBUG org.hibernate.validator.internal.engine.ValidatorFactoryImpl - HV000234: Using org.hibernate.validator.messageinterpolation.ResourceBundleMessageInterpolator as ValidatorFactory-scoped message interpolator.
15:04:36.090 [background-preinit] DEBUG org.hibernate.validator.internal.engine.ValidatorFactoryImpl - HV000234: Using org.hibernate.validator.internal.engine.resolver.TraverseAllTraversableResolver as ValidatorFactory-scoped traversable resolver.
15:04:36.090 [background-preinit] DEBUG org.hibernate.validator.internal.engine.ValidatorFactoryImpl - HV000234: Using org.hibernate.validator.internal.util.ExecutableParameterNameProvider as ValidatorFactory-scoped parameter name provider.
15:04:36.090 [background-preinit] DEBUG org.hibernate.validator.internal.engine.ValidatorFactoryImpl - HV000234: Using org.hibernate.validator.internal.engine.DefaultClockProvider as ValidatorFactory-scoped clock provider.
15:04:36.090 [background-preinit] DEBUG org.hibernate.validator.internal.engine.ValidatorFactoryImpl - HV000234: Using org.hibernate.validator.internal.engine.scripting.DefaultScriptEvaluatorFactory as ValidatorFactory-scoped script evaluator factory.
15:04:36.404 [main] ERROR org.springframework.boot.SpringApplication - Application run failed
java.lang.NoSuchMethodError: org.springframework.boot.builder.SpringApplicationBuilder.<init>([Ljava/lang/Object;)V
    at org.springframework.cloud.bootstrap.BootstrapApplicationListener.bootstrapServiceContext(BootstrapApplicationListener.java:120)
    at org.springframework.cloud.bootstrap.BootstrapApplicationListener.onApplicationEvent(BootstrapApplicationListener.java:84)
    at org.springframework.cloud.bootstrap.BootstrapApplicationListener.onApplicationEvent(BootstrapApplicationListener.java:62)
    at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172)
    at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165)
    at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139)
    at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:127)
    at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:74)
    at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:54)
    at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:351)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:317)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1246)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1234)
    at com.fangxing.springcloud.eurukaserver.EurukaServerApplication.main(EurukaServerApplication.java:16)
Process finished with exit code 1

其根本原因是依赖包的版本冲突,我的这个pom.xml文件如下:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.fangxing.springcloud</groupId>
    <artifactId>euruka-server</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>
    <name>euruka-server</name>
    <description>Demo project for Eureka Server</description>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.0.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframewor k.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-eureka-server</artifactId>
        </dependency>
    </dependencies>
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>Camden.SR3</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
</project>

这里用到的SpringBoot版本为2.0.0.0版本,我们调整一下版本,改用下面的pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.fangxing.springcloud</groupId>
    <artifactId>euruka-server</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>
    <name>euruka-server</name>
    <description>Demo project for Eureka Server</description>
    <!--基于Springboot-->
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.4.0.RELEASE</version>
        <relativePath/>
    </parent>
    <properties>
        <!--设置字符编码及java版本-->
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <java.version>1.8</java.version>
    </properties>
    <dependencies>
        <!--增加eureka-server的依赖-->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-eureka-server</artifactId>
        </dependency>
        <!--用于测试的,本例可省略-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>
    <!--依赖管理,用于管理spring-cloud的依赖,其中Camden.SR3是版本号-->
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>Camden.SR3</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
</project>

启用正常。

以上为个人经验,希望能给大家一个参考,也希望大家多多支持我们。

(0)

相关推荐

  • 简单了解springboot eureka交流机制

    一 前言 这篇文章参考了官方文档,主要是描述了eureka client 和 eureka server 之间的交流机制: peer to peer 的 对等复制交流机制: eureka 官方文档 二 server client 之间的交流 euraka 的 client 与 server 之间的交流主要通过如下方面: 2.1 Register Register (服务注册) ; Eureka client 会向 Eureka server 注册 关于自生运行实例的信息,比如 ip 地址,主机名

  • SpringBoot+Eureka实现微服务负载均衡的示例代码

    1,什么是Eureka,什么是服务注册与发现 Spring Boot作为目前最火爆的web框架.那么它与Eureka又有什么关联呢? Eureka是Netflix开源的一个RESTful服务,主要用于服务的注册发现. Eureka由两个组件组成:Eureka服务器和Eureka客户端.Eureka服务器用作服务注册服务器. Eureka客户端是一个java客户端,用来简化与服务器的交互.作为轮询负载均衡器,并提供服务的故障切换支持. Netflix在其生产环境中使用的是另外的客户端,它提供基于流

  • springboot2.0和springcloud Finchley版项目搭建(包含eureka,gateWay,Freign,Hystrix)

    前段时间spring boot 2.0发布了,与之对应的spring cloud Finchley版本也随之而来了,两者之间的关系和版本对应详见我这边文章:spring boot和spring cloud对应的版本关系 项目地址:spring-cloud-demo spring boot 1.x和spring cloud Dalston和Edgware版本搭建的微服务项目现在已经很流行了,现在很多企业都已经在用了,这里就不多说了. 使用版本说明: spring boot 2.0.x spring

  • 解决SpringBoot集成Eureka导致返回结果由json变为xml的问题

    SpringBoot集成Eureka导致返回结果由json变为xml 解决方案 在请求的Mapping上加上 produces = { "application/json;charset=UTF-8" } 例如: @GetMapping(value = "/user-instance", produces = { "application/json;charset=UTF-8" }) 以下是json和xml @GetMapping(value =

  • springboot cloud使用eureka整合分布式事务组件Seata 的方法

    前言 近期一直在忙项目,我也是打工仔.不多说,我们开始玩一玩seata. 正文 什么都不说,我们按照惯例,先上一个图(图里不规范的使用请忽略): 简单一眼就看出来, 比我们平时用的东西,多了 Seata Server 微服务 . 同样这个 Seata Server 微服务 ,也是需要注册到eureka上面去的. 那么我们首先就搞一搞这个 seata server ,那么剩下的就是一些原本的业务服务整合配置了. 该篇用的 seata server 版本,用的是1.4.1 , 可以去git下载下.当

  • springBoot整合Eureka启动失败的解决方案

    其实springBoot 整合Eureka 是比较简单 ,可是我发现很多人整合后会启动不了,我这里列出比较常见的报错的原因 报:A child container failed during start 如图下这样 这个原因是因为pom.xml 没有添加 <dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> &

  • Spring Boot 2.6.x整合Swagger启动失败报错问题的完美解决办法

    目录 问题 原因 解决方案 方案一(治标) 方案二(治本) 总结 问题 Spring Boot 2.6.x版本引入依赖 springfox-boot-starter (Swagger 3.0) 后,启动容器会报错: Failed to start bean ‘ documentationPluginsBootstrapper ‘ ; nested exception… 原因 Springfox 假设 Spring MVC 的路径匹配策略是 ant-path-matcher,而 Spring Bo

  • Spring Boot 项目启动失败的解决方案

    Spring Boot 项目是不是经常失败,显示一大堆的错误信息,如端口重复绑定时会打印以下异常: *************************** APPLICATION FAILED TO START *************************** Description: Embedded servlet container failed to start. Port 8080 was already in use. Action: Identify and stop the

  • springboot整合shiro登录失败次数限制功能的实现代码

    这次讲讲如何限制用户登录尝试次数,防止坏人多次尝试,恶意暴力破解密码的情况出现,要限制用户登录尝试次数,必然要对用户名密码验证失败做记录,Shiro中用户名密码的验证交给了CredentialsMatcher 所以在CredentialsMatcher里面检查,记录登录次数是最简单的做法.当登录失败次数达到限制,修改数据库中的状态字段,并返回前台错误信息.  因为之前的博客都是用的明文,这里就不对密码进行加密了,如果有需要加密,将自定义密码比较器从SimpleCredentialsMatcher

  • 解决springboot整合cxf启动报错,原因是版本问题

    springboot整合cxf启动报错 错误信息如下 [DEBUG] 2021-01-26 11:28:47,848 [main] org.springframework.boot.diagnostics.LoggingFailureAnalysisReporter - Application failed to start due to an exception org.springframework.beans.factory.NoSuchBeanDefinitionException: N

  • PostgreSQL 启动失败的解决方案

    环境 Red Hat CloudForms 4.x 问题 postgresql 启动失败,并导致evmserverd崩溃. [----] I, [2016-11-29T03:12:31.816753 #1201:e4f994] INFO -- : MIQ(PostgresAdmin.runcmd_with_logging) Running command... service rh-postgresql94-postgresql start [----] E, [2016-11-29T03:12

  • Springboot的spring-boot-maven-plugin导入失败的解决方案

    Springboot spring-boot-maven-plugin导入失败 因为之前换了本地仓库,再打开项目的时候就变成红色了,问题是其他依赖都导好了,只有这个家伙红的刺眼. 找到仓库下的这个文件夹,把里面的文件删掉(或者直接删掉spring-boot-maven-plugin这个文件夹) 在这里刷新,然后就是漫长的等待,网速不好可以再重复此步骤 spring-boot-maven-plugin插件作用 POM 文件中添加了"org.springframework.boot:spring-b

  • SpringBoot整合thymeleaf 报错的解决方案

    近日 在springboot项目中使用thymeleaf时,莫名报了以下错误: 在网上查找文章明白了报错的原因,这是由于如果使用thymeleaf 为模板,那么解析时就要求html必须为严格的html5格式,即必须有完整的结束标记, 不然就会报错. 在html页面中,诸如input,meta,link等标签 ,是可以不用闭合就可以被解析的(自闭合的),但是由于这里严格要求html5格式 于是解决办法如下: 1) 在报错的标签上加入 结束标签. 2) 修改为不严格的模式. 在配置文件中加入如下配置

  • docker中mysql初始化及启动失败问题解决方案

    最近做项目,遇到这样问题,docker 中的mysql 不能启动,经过上网查资料,终于解决了这个问题,这里记录下,也许还能帮助到大家, 在docker中有一个mysql服务,其数据文件是挂在在主机外面的文件,在docker中的root有访问该数据文件的权限,但是docker中mysql访问数据文件的时候提示权限不足,于是只有以root用户来启动mysql了. 数据初始化: mysql_install_db --user=root --explicit_defaults_for_timestamp

  • Springboot整合quartz产生错误及解决方案

    1.spring boot整合quartz执行多个定时任务时报: org.quartz.ObjectAlreadyExistsException: Unable to store Job : 'group1.job1', because one already exists with this identification. 定时任务虽然执行,但报了错误.第一次执行时没有报错误,第二次及之后执行前会报这个错误, 解决办法: 在初始化调度的时候clean一下: scheduler.clear();

随机推荐