Skip to content

Commit aa55563

Browse files
authored
Merge pull request #12 from fangjian0423/master
Update SpringBoot常见错误及解决方法.md
2 parents 1938940 + bc3d537 commit aa55563

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

docs/diagnosis/plugin/microservice/SpringBoot常见错误及解决方法.md

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Spring Boot 作为 Java 生态中最流行的开发框架,意味着被数以
1212
- [Jar 包启动不了](#jar-包启动不了)
1313
- [自动化配置类没有被加载](#自动化配置类没有被加载)
1414
- [定义的 Component 没有被扫描到](#定义的-component-没有被扫描到)
15+
- [Actuator Endpoint 访问不了](#actuator-endpoint-访问不了)
1516
- [推荐项目](#推荐项目)
1617
- [加入我们](#加入我们)
1718

@@ -29,9 +30,7 @@ Nacos 服务注册的 IP 可以通过 `spring.cloud.nacos.discovery.ip` 设置
2930

3031
配置问题排查:
3132

32-
查看 Stackoverflow 中的各个数据来源,确定配置的属于哪个 PropertySource 或者 Debug 查看 Environment 中的各个 PropertySource 中的配置。
33-
34-
思考: 其实 Spring Boot 可以实现  ConfigurationEndpoint 通过暴露 Endpoint 来查看用户侧到底配置了哪些配置内容。
33+
进入 http://host:port/actuator/env 这个 endpoint 查看具体的配置项属于哪个 PropertySource
3534

3635

3736
## Jar 包启动不了
@@ -53,10 +52,11 @@ Nacos 服务注册的 IP 可以通过 `spring.cloud.nacos.discovery.ip` 设置
5352

5453
条件注解是 Spring Boot 的核心特性之一,第三方的 starter 或我们自定义的 starter 内部都会加载一些 AutoConfiguration,有时候会存在一些 AutoConfiguration 没有被加载的情况。导致出现 NoSuchBeanDefinitionException, UnsatisfiedDependencyException 等异常
5554

56-
排查步骤(两种方式):
55+
排查步骤(三种方式):
5756

58-
1. 把 spring 的日志级别跳到 debug: `logging.level.org.springframework: debug`
57+
1. 把 spring 的日志级别调到 debug 级别: `logging.level.org.springframework: debug`
5958
2. 从 ApplicationContext 中获取 `ConditionEvaluationReport`,得到内部的 `ConditionEvaluationReport.ConditionAndOutcomes` 类中的输出信息
59+
3. 进入 http://host:port/actuator/conditions 这个 endpoint 查看条件注解的 match 情况
6060

6161
这是日志打印的不满足条件的 AutoConfiguratoin:
6262

@@ -93,6 +93,16 @@ Unconditional classes:
9393

9494
exclude 包下的类不会被扫描到,card 包下的类会被扫描到。
9595

96+
## Actuator Endpoint 访问不了
97+
98+
访问 Actuator,出现 404 错误。
99+
100+
解决方案:
101+
102+
1. Spring Boot 2.x 版本对 Actuator 做了大量的修改,其中访问的路径从 http://host:port/endpointid 变成了 http://host:port/actuator/endpointid 。 确保访问的路径正确
103+
2. Endpoint 有 Security 要求,在配置里加上 `management.endpoints.web.exposure.include=*` 即可
104+
105+
96106

97107
## 推荐项目
98108
* [Spring Cloud Alibaba 开源项目地址](https://github.com/alibaba/spring-cloud-alibaba)

0 commit comments

Comments
 (0)