[Dark Horse Headlines] Solve the problem that the P11@EnableDiscoveryClient annotation cannot be imported into popular, and the bootstrap.yml configuration file icon cannot be displayed as a small green leaf icon with clouds

15370650:



1. Problem description

  • If you follow the dependencies written in the pom file of heima-leadnews-servicethe module , you will find 2 bugs:

    1. First UserApplication, the service discovery switch annotation on the startup class @EnableDiscoveryClientdoes not exist.
      image-20230618155237484

    2. Second, the icon of the configurationresource file created in the directory cannot be correctly displayed as a small green leaf icon, but an ordinary YAML file.bootstrap.yml
      image-20230618155045649


2. Cause of the problem

heima-leadnews-serviceThe lack of dependencies of the module spring-cloud-contextcauses bootstrap.ymlthe icon of the configuration file to not be displayed correctly as a small green leaf icon; the lack of dependencies spring-cloud-commonscauses the service discovery switch annotation @EnableDiscoveryClientto not exist.


3. Solutions

heima-leadnews-serviceAdd the OpenFeign dependency to the module 's pom file. Because the OpenFeign dependency comes with the Spring Cloud dependency mentioned above, as shown in the following figure:

<!-- Feign远程调用客户端 -->
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>

image-20230618154248853


heima-leadnews-serviceThe complete pom file dependencies of the module are as follows:

<!-- 引入依赖模块 -->
<dependencies>
    <!-- 数据模型子模块 -->
    <dependency>
        <groupId>com.heima</groupId>
        <artifactId>heima-leadnews-model</artifactId>
    </dependency>

    <!-- 公共子模块 -->
    <dependency>
        <groupId>com.heima</groupId>
        <artifactId>heima-leadnews-common</artifactId>
    </dependency>

    <!-- 远程调用子模块 -->
    <dependency>
        <groupId>com.heima</groupId>
        <artifactId>heima-leadnews-feign-api</artifactId>
    </dependency>

    <!-- Spring Boot Web starter -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

    <!-- Spring Boot Test测试 -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>

    <!-- Nacos注册中心 -->
    <dependency>
        <groupId>com.alibaba.cloud</groupId>
        <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
    </dependency>

    <!-- Nacos配置中心 -->
    <dependency>
        <groupId>com.alibaba.cloud</groupId>
        <artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
    </dependency>

    <!-- Feign远程调用客户端 -->
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-openfeign</artifactId>
    </dependency>
</dependencies>

After refreshing Maven UserApplication, the service discovery switch annotation on the startup class @EnableDiscoveryClientcan used normally.

image-20230618155759039


heima-leadnews-userThe icon of the configuration file created under resourcethe directory of the user microservice can be correctly displayed as a small green leaf icon with a cloud.bootstrap.yml

image-20230618155835020


After all the bugs are eliminated, continue to develop according to the progress of the video.

Guess you like

Origin blog.csdn.net/Sihang_Xie/article/details/131273488