首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法注册类路径资源中定义的bean 'eurekaRegistration‘

无法注册类路径资源中定义的bean 'eurekaRegistration‘
EN

Stack Overflow用户
提问于 2020-07-13 10:02:45
回答 2查看 800关注 0票数 1

我已经配置了我的eureka discovery server,它已经在本地主机http:\\localhost:8761中启动并运行。但是当我试图配置eureka discovery client (在intellij的另一个项目中)时,它是正确构建的,但是应用程序没有启动,并且它给出了下面的错误。

请在下面找到堆栈跟踪。

代码语言:javascript
复制
      .   ____          _            __ _ _
     /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
    ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
     \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
      '  |____| .__|_| |_|_| |_\__, | / / / /
     =========|_|==============|___/=/_/_/_/
     :: Spring Boot ::        (v2.1.6.RELEASE)

    2020-07-13 07:12:37.271  INFO 14932 --- [           main] c.l.m.s.c.CoreServicesApplication        : Starting CoreServicesApplication on DESKTOP-5ENMOJ0 with PID 14932 (D:\AngularCourse\core-services\out\production\classes started by Karthikeyan in D:\AngularCourse\core-services)
    2020-07-13 07:12:37.277  INFO 14932 --- [           main] c.l.m.s.c.CoreServicesApplication        : No active profile set, falling back to default profiles: default
    2020-07-13 07:12:39.277  INFO 14932 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data repositories in DEFAULT mode.
    2020-07-13 07:12:39.430  INFO 14932 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 134ms. Found 3 repository interfaces.
    2020-07-13 07:12:39.611  WARN 14932 --- [           main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.support.BeanDefinitionOverrideException: Invalid bean definition with name 'eurekaRegistration' defined in class path resource [org/springframework/cloud/netflix/eureka/EurekaClientAutoConfiguration$EurekaClientConfiguration.class]: Cannot register bean definition [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.springframework.cloud.netflix.eureka.EurekaClientAutoConfiguration$EurekaClientConfiguration; factoryMethodName=eurekaRegistration; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/cloud/netflix/eureka/EurekaClientAutoConfiguration$EurekaClientConfiguration.class]] for bean 'eurekaRegistration': There is already [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.springframework.cloud.netflix.eureka.EurekaClientAutoConfiguration$RefreshableEurekaClientConfiguration; factoryMethodName=eurekaRegistration; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/cloud/netflix/eureka/EurekaClientAutoConfiguration$RefreshableEurekaClientConfiguration.class]] bound.
    2020-07-13 07:12:39.630  INFO 14932 --- [           main] ConditionEvaluationReportLoggingListener : 

    Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
    2020-07-13 07:12:39.632 ERROR 14932 --- [           main] o.s.b.d.LoggingFailureAnalysisReporter   : 

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

    Description:

    The bean 'eurekaRegistration', defined in class path resource [org/springframework/cloud/netflix/eureka/EurekaClientAutoConfiguration$EurekaClientConfiguration.class], could not be registered. A bean with that name has already been defined in class path resource [org/springframework/cloud/netflix/eureka/EurekaClientAutoConfiguration$RefreshableEurekaClientConfiguration.class] and overriding is disabled.

    Action:

    Consider renaming one of the beans or enabling overriding by setting spring.main.allow-bean-definition-overriding=true


    Process finished with exit code 1

请找到我的build.gradle文件。

代码语言:javascript
复制
    plugins {
        id 'org.springframework.boot' version '2.1.6.RELEASE'
        id 'io.spring.dependency-management' version '1.0.9.RELEASE'
        id 'java'
        id 'war'
    }

    group = 'com.lti.mod.services'
    version = '0.0.1-SNAPSHOT'
    sourceCompatibility = '1.8'

    configurations {
        compileOnly {
            extendsFrom annotationProcessor
        }
    }

    repositories {
        mavenCentral()
    }

    dependencies {
        implementation('io.jsonwebtoken:jjwt:0.9.1')
        implementation('org.springframework.cloud:spring-cloud-netflix-eureka-server:2.1.5.RELEASE')
        implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
        implementation 'org.springframework.boot:spring-boot-starter-data-rest'
        implementation 'org.springframework.boot:spring-boot-starter-security'
        implementation 'org.springframework.boot:spring-boot-starter-web'
        implementation 'org.liquibase:liquibase-core'
        /*compile group: 'io.jsonwebtoken', name: 'jjwt', version: '0.9.1'*/
        compileOnly 'org.projectlombok:lombok'
        runtimeOnly 'mysql:mysql-connector-java'
        annotationProcessor 'org.projectlombok:lombok'
        providedRuntime 'org.springframework.boot:spring-boot-starter-tomcat'
        testImplementation('org.springframework.boot:spring-boot-starter-test') {
            exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
        }
        testImplementation 'org.springframework.security:spring-security-test'
    }

    test {
        useJUnitPlatform()
    }

请找到我的application.properties文件。

代码语言:javascript
复制
    spring.application.name=core-services

    #datasource
    spring.datasource.url=jdbc:mysql://localhost:3306/moddb?useUnicode=true&useLegacyDatetimeCode=false&serverTimezone=UTC&createDatabaseIfNotExist=true&allowPublicKeyRetrieval=true&userSSL=true
    spring.datasource.username=root
    spring.datasource.password=root
    spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver

    spring.jpa.hibernate.ddl-auto=none

    #liquibase
    spring.liquibase.change-log=classpath:/db/changelog/db.changelog-master.xml

    #jwt
    app.jwt.secret=RandomSecretKey
    #1 day
    app.jwt.expiration-in-ms=86400000
    app.jwt.token.prefix=Bearer
    app.jwt.header.string=Authorization

    #eureka
    eureka.client.servie-url.default-zone=http://localhost:8761
    #indicates the frequency the client sends heartbeat to server to indicate that it is alive.
    eureka.instance.lease-renewal-interval-in-seconds=30
    #incicates the duration the server waits since it received the last heartbeat before it can evict an instance from its registry
    eureka.instance.lease-expiration-duration-in-seconds=90

    #load balancing
    ribbon.eureka.enabled=true
EN

回答 2

Stack Overflow用户

发布于 2020-07-13 12:15:50

错误本身说明您有两个同名的bean。试着重命名其中的一个。或者使用它在application.properties文件中建议的属性。即使它不工作,也可以给我Discovery客户端和服务器类的快照。

票数 0
EN

Stack Overflow用户

发布于 2022-02-26 17:47:21

答案可以在这里找到-https://chowdera.com/2021/12/202112211422209581.html

依赖项不正确需要更改

来自spring--netflix-eureka-的服务器

-cloud-starter-netflix-eureka-server

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62868281

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档