current catalog
1. Problem description
-
If you follow the dependencies written in the pom file of
heima-leadnews-service
the module , you will find 2 bugs:-
First
UserApplication
, the service discovery switch annotation on the startup class@EnableDiscoveryClient
does not exist.
-
Second, the icon of the configuration
resource
file created in the directory cannot be correctly displayed as a small green leaf icon, but an ordinary YAML file.bootstrap.yml
-
2. Cause of the problem
heima-leadnews-service
The lack of dependencies of the module spring-cloud-context
causes bootstrap.yml
the icon of the configuration file to not be displayed correctly as a small green leaf icon; the lack of dependencies spring-cloud-commons
causes the service discovery switch annotation @EnableDiscoveryClient
to not exist.
3. Solutions
heima-leadnews-service
Add 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>
heima-leadnews-service
The 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 @EnableDiscoveryClient
can used normally.
heima-leadnews-user
The icon of the configuration file created under resource
the directory of the user microservice can be correctly displayed as a small green leaf icon with a cloud.bootstrap.yml
After all the bugs are eliminated, continue to develop according to the progress of the video.