discovery client not initialized

เมื่อใช้ spring boot 2.5.x และใช้ spring cloud bud แล้วเจอปัญหานี้ “discovery client not initialized status unknown”

1
springboot 2.5.x
Discovery Client not initialized

วิธีแก้เพิ่ม config anotation @Configuration นี้เข้าไป

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import org.springframework.cloud.client.discovery.event.InstanceRegisteredEvent;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.annotation.Configuration;
import javax.annotation.PostConstruct;
 
@Configuration
public class DiscoveryCompositeConfig {
 
    private final ApplicationEventPublisher applicationEventPublisher;
 
    public DiscoveryCompositeConfig(ApplicationEventPublisher applicationEventPublisher) {
        this.applicationEventPublisher = applicationEventPublisher;
    }
 
    @PostConstruct
    public void postConstruct() {
        publishCustomEvent("Instance register event triggered");
    }
 
    public void publishCustomEvent(final String message) {
        final InstanceRegisteredEvent<?> instanceRegisteredEvent = new InstanceRegisteredEvent<>(this, message);
        applicationEventPublisher.publishEvent(instanceRegisteredEvent);
    }
}

ผลที่ได้ กลายเป็น UP แล้ว

สำหรับใครหาวิธีแก้ ก็ลองเอาไปใช้ดู เผื่อใช้ได้

Dependency ที่ใช้

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
    <dependencyManagement>
        <dependencies>
 
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>2020.0.3</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>
 
    <dependencies>
 
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-bus-kafka</artifactId>
        </dependency>
 
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
            <optional>true</optional>
        </dependency>
    </dependencies>

Comments are closed.