'bean 'eurekaRegistration', defined in class path resource could not be registered

I have configured my eureka discovery server and it is up and running in local host http:\\localhost:8761. But when am trying to configure eureka discovery client (in another project in intellij) it was build properly but application is not starting and its giving the below error.

Please find the stack trace below.

      .   ____          _            __ _ _
     /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
    ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
     \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
      '  |____| .__|_| |_|_| |_\__, | / / / /
     =========|_|==============|___/=/_/_/_/
     :: 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

Please find my build.gradle file.

    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()
    }

Please find my application.properties file.

    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


Solution 1:[1]

The answer can be found here-https://chowdera.com/2021/12/202112211422209581.html

The dependency is incorrect needs to be changed

from spring-cloud-netflix-eureka-server

to spring-cloud-starter-netflix-eureka-server

Solution 2:[2]

The error itself says that you have two beans with the same name. Try renaming one of those. Or use the property it suggests in application.properties file. Even if it's not working then give me the snapshot of Discovery Client and Server Classes.

Solution 3:[3]

<dependency>
                  <groupId>org.springframework.cloud</groupId>
                  <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
                  <version>3.1.1</version>
            </dependency>

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Vishal Verma
Solution 2 Gowtham
Solution 3 Maninder