带有 Eureka 服务器的 Spring Boot 1.4.2.RELEASE - 异常:org.springframework.beans.factory.NoSuchBeanDefinition

Posted

技术标签:

【中文标题】带有 Eureka 服务器的 Spring Boot 1.4.2.RELEASE - 异常:org.springframework.beans.factory.NoSuchBeanDefinitionException【英文标题】:Spring Boot 1.4.2.RELEASE with Eureka Server - Exception: org.springframework.beans.factory.NoSuchBeanDefinitionException 【发布时间】:2017-04-04 00:11:57 【问题描述】:

尝试使用 Eureka 服务器运行 Spring Boot 1.4.2.RELEASE 时出现以下错误:

2016-11-20 16:25:59.306  INFO 14263 --- [           main] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@2177849e: startup date [Sun Nov 20 16:25:59 CET 2016]; root of context hierarchy
2016-11-20 16:25:59.581  INFO 14263 --- [           main] f.a.AutowiredAnnotationBeanPostProcessor : JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
2016-11-20 16:25:59.606  INFO 14263 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'configurationPropertiesRebinderAutoConfiguration' of type [class org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration$$EnhancerBySpringCGLIB$$fc4b31a3] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v1.4.2.RELEASE)

2016-11-20 16:26:04.988  INFO 14263 --- [           main] i.v.p.s.EurekaServerApplication          : No active profile set, falling back to default profiles: default
2016-11-20 16:26:05.005  INFO 14263 --- [           main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@3e14c16d: startup date [Sun Nov 20 16:26:05 CET 2016]; parent: org.springframework.context.annotation.AnnotationConfigApplicationContext@2177849e
2016-11-20 16:26:05.589  WARN 14263 --- [           main] o.s.c.a.ConfigurationClassPostProcessor  : Cannot enhance @Configuration bean definition 'refreshScope' since its singleton instance has been created too early. The typical cause is a non-static @Bean method with a BeanDefinitionRegistryPostProcessor return type: Consider declaring such methods as 'static'.
2016-11-20 16:26:05.774  INFO 14263 --- [           main] o.s.cloud.context.scope.GenericScope     : BeanFactory id=05587591-c1ba-31c3-b56f-8b79a2e1951f
2016-11-20 16:26:05.787  INFO 14263 --- [           main] f.a.AutowiredAnnotationBeanPostProcessor : JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
2016-11-20 16:26:05.857  INFO 14263 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration' of type [class org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration$$EnhancerBySpringCGLIB$$fc4b31a3] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2016-11-20 16:26:06.180  INFO 14263 --- [           main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8761 (http)
2016-11-20 16:26:06.197  INFO 14263 --- [           main] o.apache.catalina.core.StandardService   : Starting service Tomcat
2016-11-20 16:26:06.198  INFO 14263 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/8.5.6
2016-11-20 16:26:06.326  INFO 14263 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2016-11-20 16:26:06.327  INFO 14263 --- [ost-startStop-1] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 1322 ms
2016-11-20 16:26:06.347 ERROR 14263 --- [ost-startStop-1] o.s.b.c.embedded.tomcat.TomcatStarter    : Error starting Tomcat context. Exception: org.springframework.beans.factory.UnsatisfiedDependencyException. Message: Error creating bean with name 'org.springframework.cloud.netflix.eureka.server.EurekaServerConfiguration': Unsatisfied dependency expressed through field 'applicationInfoManager'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.netflix.appinfo.ApplicationInfoManager' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: @org.springframework.beans.factory.annotation.Autowired(required=true)
2016-11-20 16:26:06.375  WARN 14263 --- [           main] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is org.springframework.boot.context.embedded.EmbeddedServletContainerException: Unable to start embedded Tomcat
2016-11-20 16:26:06.483 ERROR 14263 --- [           main] o.s.b.d.LoggingFailureAnalysisReporter   : 

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

Description:

Field applicationInfoManager in org.springframework.cloud.netflix.eureka.server.EurekaServerConfiguration required a bean of type 'com.netflix.appinfo.ApplicationInfoManager' that could not be found.


Action:

Consider defining a bean of type 'com.netflix.appinfo.ApplicationInfoManager' in your configuration.

这是 pom 文件

<?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>my.test.springMicroservices</groupId>
    <artifactId>EurekaServer</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>EurekaServer</name>
    <description>Eureka discovery server example</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.4.2.RELEASE</version>
        <relativePath />
    </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-actuator</artifactId>
        </dependency>
        <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>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>Camden.SR2</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>

application.yml

server:
  port: 8761
spring:
  application:
    name: eureka-server1
eureka:
  client:
    enabled: false
    fetch-registry: false

我的Spring boot应用类

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;

@SpringBootApplication
@EnableEurekaServer
public class EurekaServerApplication 
    public static void main(String[] args) 
        SpringApplication.run(EurekaServerApplication.class, args);
    


这是我的环境:

MacOS Sierra 10.12.1 Spring Tool Suite - 版本:3.8.2.RELEASE(内部版本 ID:201610040743 - 平台:Eclipse Neon.1 (4.6.1))

我错过了什么吗?

提前致谢

【问题讨论】:

eureka.client.enabled: false 引起了这个问题,您可以将其删除以解决问题。 作为问题提出:github.com/spring-cloud/spring-cloud-netflix/issues/1484 删除eureka.client.enabled: false 引发另一个错误:Parameter 0 of method traceFilterRegistration in org.springframework.cloud.netflix.eureka.server.EurekaServerConfiguration required a bean of type 'javax.servlet.Filter' that could not be found. - Bean method 'resourceUrlEncodingFilter' in 'FreeMarkerAutoConfiguration.FreeMarkerWebConfiguration' not loaded because @ConditionalOnEnabledResourceChain did not find class org.webjars.WebJarAssetLocator Action: Consider revisiting the conditions above or defining a bean of type 'javax.servlet.Filter' in your configuration. 这个问题有什么解决办法吗?上面的解决方案对我不起作用 【参考方案1】:

从配置中删除 eureka.client.enabled=false。然后它会启动服务器

【讨论】:

我面临同样的问题。我在 application.prop 中没有 eureka.client.enabled 没有 eureka.client.enable 我也有同样的问题【参考方案2】:

在我的情况下,我必须使用 spring 云版本“Edgware.SR4”以及兼容的父 pom 版本(如 1.5.16.RELEASE)来解决此问题。云版本及其相关依赖项似乎存在一些问题。

【讨论】:

【参考方案3】:

就我而言,spring boot 和 spring cloud 版本不匹配。使用https://spring.io/projects/spring-cloud检查正确的版本。

【讨论】:

以上是关于带有 Eureka 服务器的 Spring Boot 1.4.2.RELEASE - 异常:org.springframework.beans.factory.NoSuchBeanDefinition的主要内容,如果未能解决你的问题,请参考以下文章

带有 Eureka 服务器的 Spring Boot 1.4.2.RELEASE - 异常:org.springframework.beans.factory.NoSuchBeanDefinition

使用带有spring boot和eureka的@EnableZuulProxy闪烁Zuul TimeoutExceptions

带有 Eureka 的 Spring Cloud Gateway 得到 504(网关超时)

带有临时端口的 Spring-cloud brixton、eureka 和 docker

Spring Cloud:ZUUL + Eureka + NodeJS

带有 Eureka 发现的 Spring Cloud Gateway 启用 CORS 策略