Tag Archives: eureka

[Solved] Error in registering Eureka for spring cloud micro service: classnotfoundexception: org.apache.http.conn.scheme.schemeregistry

1. Problem description

As mentioned above, it is normal to start the Eureka server alone. When you start the micro service module and register the service with Eureka, an error is reported.

My microservice module POM depends on the following:

<dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
        </dependency>
        <dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
            <version>2.1.1</version>
        </dependency>

    </dependencies>

Microservice module configuration file:

eureka.client.service-url.defaultZone=http://localhost:8000/eureka

The total POM of the project is as follows:

<dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</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>Greenwich.SR5</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

2. Solution

See a similar problem on stack overflow:

https://stackoverflow.com/questions/28217891/java-lang-classnotfoundexception-org-apache-http-config-registrybuilder

It is speculated that there may also be a problem with the dependent package under D: \ D1 \ Java \ maven \ repo \ ORG \ Apache \ httpcomponents

According to the time of the file modification date, the following package should be called for the use of Eureka

Delete these folders and reintroduce the POM dependency of microservice module and Eureka server

Start the microservice here and the problem is solved

16:31:17.183- INFO 38700 --- [           main]com.netflix.discovery.DiscoveryClient    :Getting all instance registry info from the eureka server
16:31:17.460- INFO 38700 --- [           main]com.netflix.discovery.DiscoveryClient    :The response status is 200
16:31:17.462- INFO 38700 --- [           main]com.netflix.discovery.DiscoveryClient    :Starting heartbeat executor: renew interval is: 30
16:31:17.465- INFO 38700 --- [           main]c.n.discovery.InstanceInfoReplicator     :InstanceInfoReplicator onDemand update allowed rate per min is 4
16:31:17.470- INFO 38700 --- [           main]com.netflix.discovery.DiscoveryClient    :Discovery Client initialized at timestamp 1628843477468 with initial instances count: 0
16:31:17.472- INFO 38700 --- [           main]o.s.c.n.e.s.EurekaServiceRegistry        :Registering application COURSE-LIST with eureka with status UP
16:31:17.472- INFO 38700 --- [           main]com.netflix.discovery.DiscoveryClient    :Saw local status change event StatusChangeEvent [timestamp=1628843477472, current=UP, previous=STARTING]
16:31:17.475- INFO 38700 --- [nfoReplicator-0]com.netflix.discovery.DiscoveryClient    :DiscoveryClient_COURSE-LIST/LAPTOP-LMMPH4VI:course-list:8080: registering service...
16:31:17.523- INFO 38700 --- [           main]o.s.b.w.embedded.tomcat.TomcatWebServer  :Tomcat started on port(s): 8080 (http) with context path ''
16:31:17.524- INFO 38700 --- [           main].s.c.n.e.s.EurekaAutoServiceRegistration :Updating port to 8080
16:31:17.567- INFO 38700 --- [nfoReplicator-0]com.netflix.discovery.DiscoveryClient    :DiscoveryClient_COURSE-LIST/LAPTOP-LMMPH4VI:course-list:8080 - registration status: 204
16:31:19.133- INFO 38700 --- [           main]com.fanyu.course.CourseListApplication   :Started CourseListApplication in 13.313 seconds (JVM running for 14.906)

After introducing security, the service cannot be registered with Eureka

When building the Eureka service of springcloud, security was introduced for security. However, it was found that the Eureka client could not register. The error log is as follows:

DiscoveryClient_ EUREKA-CLIENT/10.168.211.109:8001 – was unable to send heartbeat!

Later, I inquired about the Security version of the project (spring boot starter security in version 2.3.2.release introduces the security configuration of 5.3. X). If the version is too high, it will be changed by default   When CSRF (Cross Site Request Forgery) is turned on, you need to turn it off. The steps are as follows:

Add the following code into the startup file:


    @EnableWebSecurity
    static class WebSecurityConfig extends WebSecurityConfigurerAdapter {
        @Override
        protected void configure(HttpSecurity http) throws Exception {
            http.csrf().disable(); // Close csrf
            super.configure(http);
        }
    }

The test is effective.

[Solved] Failed to start bean ‘eurekaAutoServiceRegistration‘; nested exception is java.lang.NullPointerExce

When using spring-cloud-starter-netflix-eureka-client, the following exception was encountered when starting the project. Failed to start bean ‘eurekaAutoServiceRegistration’; nested exception is java.lang.NullPointerExce

org.springframework.context.ApplicationContextException: Failed to start bean 'eurekaAutoServiceRegistration'; nested exception is java.lang.NullPointerException
	at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:176) ~[spring-context-4.3.17.RELEASE.jar:4.3.17.RELEASE]
	at org.springframework.context.support.DefaultLifecycleProcessor.access$200(DefaultLifecycleProcessor.java:50) ~[spring-context-4.3.17.RELEASE.jar:4.3.17.RELEASE]
	at org.springframework.context.support.DefaultLifecycleProcessor$LifecycleGroup.start(DefaultLifecycleProcessor.java:346) ~[spring-context-4.3.17.RELEASE.jar:4.3.17.RELEASE]
	at org.springframework.context.support.DefaultLifecycleProcessor.startBeans(DefaultLifecycleProcessor.java:149) ~[spring-context-4.3.17.RELEASE.jar:4.3.17.RELEASE]
	at org.springframework.context.support.DefaultLifecycleProcessor.onRefresh(DefaultLifecycleProcessor.java:112) ~[spring-context-4.3.17.RELEASE.jar:4.3.17.RELEASE]
	at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:880) ~[spring-context-4.3.17.RELEASE.jar:4.3.17.RELEASE]
	at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.finishRefresh(EmbeddedWebApplicationContext.java:144) ~[spring-boot-1.5.13.RELEASE.jar:1.5.13.RELEASE]
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:546) ~[spring-context-4.3.17.RELEASE.jar:4.3.17.RELEASE]
	at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) ~[spring-boot-1.5.13.RELEASE.jar:1.5.13.RELEASE]
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:693) [spring-boot-1.5.13.RELEASE.jar:1.5.13.RELEASE]
	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:360) [spring-boot-1.5.13.RELEASE.jar:1.5.13.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:303) [spring-boot-1.5.13.RELEASE.jar:1.5.13.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1118) [spring-boot-1.5.13.RELEASE.jar:1.5.13.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1107) [spring-boot-1.5.13.RELEASE.jar:1.5.13.RELEASE]
	at com.shanba.SbnsyhManageApplication.main(SbnsyhManageApplication.java:12) [classes/:na]
Caused by: java.lang.NullPointerException: null
	at org.springframework.cloud.netflix.eureka.serviceregistry.EurekaServiceRegistry.maybeInitializeClient(EurekaServiceRegistry.java:56) ~[spring-cloud-netflix-eureka-client-1.3.0.RELEASE.jar:1.3.0.RELEASE]
	at org.springframework.cloud.netflix.eureka.serviceregistry.EurekaServiceRegistry.register(EurekaServiceRegistry.java:37) ~[spring-cloud-netflix-eureka-client-1.3.0.RELEASE.jar:1.3.0.RELEASE]
	at org.springframework.cloud.netflix.eureka.serviceregistry.EurekaAutoServiceRegistration.start(EurekaAutoServiceRegistration.java:73) ~[spring-cloud-netflix-eureka-client-1.3.0.RELEASE.jar:1.3.0.RELEASE]
	at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:173) ~[spring-context-4.3.17.RELEASE.jar:4.3.17.RELEASE]
	... 14 common frames omitted

Reason: spring cloud’s jar package is introduced in POM in sequence

Wrong reference

<!--thymeleaf Template engine configuration-->
<dependency>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<!--Web依赖-->
<dependency>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
	<groupId>org.springframework.cloud</groupId>
	<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>

Normal reference

<dependency>
	<groupId>org.springframework.cloud</groupId>
	<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<!--thymeleaf Template engine configuration-->
<dependency>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<!--Web-->
<dependency>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-starter-web</artifactId>
</dependency>

Eureka failed to register error: saw local status change event statuschangeevent

The original usage of adding dependency is as follows:

dependencies {
    
    compile(” org.springframework.cloud :spring-cloud-starter-netflix-eureka- client:2.0.4.RELEASE “)

}

When starting, an error will be prompted: [warn] [2020-08-18 14:45:15.922] [main] com.netflix.discovery .DiscoveryClient [1297] – Saw local status change event StatusChangeEvent [timestamp=1597733115922, current=DOWN, previous=UP]

 

Later, it was found that the problem was how to write the service name

Add the dependency as follows:

dependencies {
    
    compile(” org.springframework.cloud :spring-cloud-starter-netflix-eureka- client:2.0.4.RELEASE “)

    compile(” org.apache.commons :commons-lang3:3.8.1″)
}

The service can be registered to Eureka

 

Saw local status change event statuschangeevent error during springcloud client registration

Start error message

2020-06-12 11:48:54.815  WARN 7728 --- [      Thread-31] com.netflix.discovery.DiscoveryClient    : Saw local status change event StatusChangeEvent [timestamp=1591933734815, current=DOWN, previous=UP]
2020-06-12 11:48:54.819  INFO 7728 --- [      Thread-31] com.netflix.discovery.DiscoveryClient    : Shutting down DiscoveryClient ...
2020-06-12 11:48:54.831  INFO 7728 --- [nfoReplicator-0] com.netflix.discovery.DiscoveryClient    : DiscoveryClient_KOALA-AI-PLATFORM-APP/192.168.100.1:18087 - registration status: 204
2020-06-12 11:48:54.832  INFO 7728 --- [nfoReplicator-0] com.netflix.discovery.DiscoveryClient    : DiscoveryClient_KOALA-AI-PLATFORM-APP/192.168.100.1:18087: registering service...
2020-06-12 11:48:54.836  INFO 7728 --- [nfoReplicator-0] com.netflix.discovery.DiscoveryClient    : DiscoveryClient_KOALA-AI-PLATFORM-APP/192.168.100.1:18087 - registration status: 204
2020-06-12 11:48:54.837  INFO 7728 --- [      Thread-31] com.netflix.discovery.DiscoveryClient    : Unregistering ...
2020-06-12 11:48:54.843  INFO 7728 --- [      Thread-31] com.netflix.discovery.DiscoveryClient    : DiscoveryClient_KOALA-AI-PLATFORM-APP/192.168.100.1:18087 - deregister  status: 200
2020-06-12 11:48:54.854  INFO 7728 --- [      Thread-31] com.netflix.discovery.DiscoveryClient    : Completed shut down of DiscoveryClient

The client can’t be registered in Eureka. After looking around, we found that spring boot starter web is missing in the client POM file, plus

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

Error resolution: request execution error. Endpoint = defaultendpoint {serviceurl=‘ http://127.0.0.1 :6668/eureka/}

>
1, confirm the defaultZone wording, yml configuration file named here requires the use of the hump, some people all lowercase, also quote the wrong
2, yml file should not read the configure port 6668, can be the 6668 server and client are replaced by the default of 8761, restart again, no error after the switch back to 6668, restart without error
3, yml file format, strictly abide by the following; If there is any Chinese in the file, make sure the Chinese is UTF-8