spring-cloud问题排查
程序员文章站
2022-03-10 14:12:55
...
### 问题1报错,应用无法启动
org.springframework.core.io.ClassPathResource.getInputStream()抛出异常:
FileNotFoundException:org/springframework/boot/actuate/autoconfigure/HealthIndicatorAutoConfiguration.class cannot be opened because it does not exist
### 原因分析
HealthIndicatorAutoConfiguration 在spring-boot不同版本路径变了
- spring-boot1.x: org.springframework.boot.actuate.autoconfigure.HealthIndicatorAutoConfiguration
- spring-boot2.x:org.springframework.boot.actuate.autoconfigure.health.HealthIndicatorAutoConfiguration
通过debug发现,源头在 HystrixAutoConfiguration,代码如下:
```java
import org.springframework.boot.actuate.autoconfigure.HealthIndicatorAutoConfiguration;
@Configuration
@ConditionalOnClass({ Hystrix.class, HealthIndicator.class })
@AutoConfigureAfter({ HealthIndicatorAutoConfiguration.class })
public class HystrixAutoConfiguration {
}
```
HystrixAutoConfiguration依赖的是spring-boot1.x版本的HealthIndicatorAutoConfiguration,通过升级spring-cloud版本,问题解决。
### 问题2
同样的问题出现在 org/springframework/cloud/netflix/eureka/EurekaClientAutoConfiguration.class
需要分析出 org.springframework.cloud.netflix.eureka.EurekaClientAutoConfiguration被谁用到的。
通过debug发现,在 AutoConfigurationSorter.addToClasses() 发现是org.springframework.cloud.netflix.ribbon.RibbonAutoConfiguration引入的,代码如下:
```java
package org.springframework.cloud.netflix.ribbon;
@Configuration
@Conditional(RibbonAutoConfiguration.RibbonClassesConditions.class)
@RibbonClients
@AutoConfigureAfter(name = "org.springframework.cloud.netflix.eureka.EurekaClientAutoConfiguration")
@AutoConfigureBefore({LoadBalancerAutoConfiguration.class, AsyncLoadBalancerAutoConfiguration.class})
@EnableConfigurationProperties({RibbonEagerLoadProperties.class, ServerIntrospectorProperties.class})
public class RibbonAutoConfiguration {
}
```
可以发现是同样的原因,实际上我们不会使用到RibbonAutoConfiguration,排除掉spring-cloud-netflix-ribbon,问题解决
org.springframework.core.io.ClassPathResource.getInputStream()抛出异常:
FileNotFoundException:org/springframework/boot/actuate/autoconfigure/HealthIndicatorAutoConfiguration.class cannot be opened because it does not exist
### 原因分析
HealthIndicatorAutoConfiguration 在spring-boot不同版本路径变了
- spring-boot1.x: org.springframework.boot.actuate.autoconfigure.HealthIndicatorAutoConfiguration
- spring-boot2.x:org.springframework.boot.actuate.autoconfigure.health.HealthIndicatorAutoConfiguration
通过debug发现,源头在 HystrixAutoConfiguration,代码如下:
```java
import org.springframework.boot.actuate.autoconfigure.HealthIndicatorAutoConfiguration;
@Configuration
@ConditionalOnClass({ Hystrix.class, HealthIndicator.class })
@AutoConfigureAfter({ HealthIndicatorAutoConfiguration.class })
public class HystrixAutoConfiguration {
}
```
HystrixAutoConfiguration依赖的是spring-boot1.x版本的HealthIndicatorAutoConfiguration,通过升级spring-cloud版本,问题解决。
### 问题2
同样的问题出现在 org/springframework/cloud/netflix/eureka/EurekaClientAutoConfiguration.class
需要分析出 org.springframework.cloud.netflix.eureka.EurekaClientAutoConfiguration被谁用到的。
通过debug发现,在 AutoConfigurationSorter.addToClasses() 发现是org.springframework.cloud.netflix.ribbon.RibbonAutoConfiguration引入的,代码如下:
```java
package org.springframework.cloud.netflix.ribbon;
@Configuration
@Conditional(RibbonAutoConfiguration.RibbonClassesConditions.class)
@RibbonClients
@AutoConfigureAfter(name = "org.springframework.cloud.netflix.eureka.EurekaClientAutoConfiguration")
@AutoConfigureBefore({LoadBalancerAutoConfiguration.class, AsyncLoadBalancerAutoConfiguration.class})
@EnableConfigurationProperties({RibbonEagerLoadProperties.class, ServerIntrospectorProperties.class})
public class RibbonAutoConfiguration {
}
```
可以发现是同样的原因,实际上我们不会使用到RibbonAutoConfiguration,排除掉spring-cloud-netflix-ribbon,问题解决
上一篇: 软件构造实验一