EurekaClient项目启动报错Invocation of destroy method failed on bean with name 'scopedTarget.eurekaClient':

Eureka Client的使用

使用IDEA创建一个Spring Initializr项目,在勾选模块的时候需要选择Eureka Discovery,如下:
EurekaClient项目启动报错Invocation of destroy method failed on bean with name 'scopedTarget.eurekaClient':_第1张图片

项目生成的pom.xml文件内容如下: 

  1.  

  2.  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

  3.  4.0.0

  4.   

  5.  org.zero.eureka

  6.  client

  7.  0.0.1-SNAPSHOT

  8.  jar

  9.  

  10.  client

  11.  Demo project for Spring Boot

  12.  

  13.  

  14.  org.springframework.boot

  15.  spring-boot-starter-parent

  16.  2.0.4.RELEASE

  17.   

  18.  

  19.   

  20.  

  21.  UTF-8

  22.  UTF-8

  23.  1.8

  24.  Finchley.SR1

  25.  

  26.  

  27.  

  28.  

  29.  org.springframework.cloud

  30.  spring-cloud-starter-netflix-eureka-client

  31.  

  32.   

  33.  

  34.  org.springframework.boot

  35.  spring-boot-starter-test

  36.  test

  37.  

  38.  

  39.   

  40.  

  41.  

  42.  

  43.  org.springframework.cloud

  44.  spring-cloud-dependencies

  45.  ${spring-cloud.version} 

  46. pom

  47.  import

  48.  

  49.  

  50.  

  51.   

  52.  

  53.  

  54.  

  55.  org.springframework.boot

  56.  spring-boot-maven-plugin

  57.  

  58.  

  59.   

项目的依赖都加载完成后,在启动类中加上@EnableDiscoveryClient,声明这是一个eureka client,否则不会进行服务注册:

  1. package org.zero.eureka.client;

  2.  

  3.  import org.springframework.boot.SpringApplication;

  4.  import org.springframework.boot.autoconfigure.SpringBootApplication;

  5.  import org.springframework.cloud.client.discovery.EnableDiscoveryClient;

  6.   

  7. @SpringBootApplication

  8. @EnableDiscoveryClient

  9.  public class ClientApplication {

  10.  

  11.  public static void main(String[] args) {

  12.  SpringApplication.run(ClientApplication.class, args);

  13.  }

  14. }

接着就是在application.yml配置文件中,配置注册中心即eureka server的地址,以及项目的名称和启动端口号。如下:

  1.  eureka: 

  2.       client:

  3.    service-url:

  4.            defaultZone: http://localhost:8761/eureka/

  5.  spring:

  6.    application:

  7.      name: eureka-client

  8.  server:

  9.    port: 9088

完成以上配置后,即可启动项目。但是我这里启动项目的时候失败了,控制台输出如下警告信息:

Invocation of destroy method failed on bean with name 'scopedTarget.eurekaClient': org.springframework.beans.factory.BeanCreationNotAllowedException: Error creating bean with name 'eurekaInstanceConfigBean': Singleton bean creation not allowed while singletons of this factory are in destruction (Do not request a bean from a BeanFactory in a destroy method implementation!)

这是因为client里不包含Tomcat的依赖,所以Spring容器无法创建一些实例,从而导致项目无法启动,只需在pom.xml文件中,加上web依赖即可:

  1.  

  2.  org.springframework.boot

  3.  spring-boot-starter-web

  4.  

项目启动成功后,可以在eureka server的信息面板中查看到已注册的实例信息,如下:

 

转:http://www.cnblogs.com/yueguanguanyun/p/9612457.html

你可能感兴趣的:(springcloud,springCloud)