项目使用sentinel遇到的问题

springboot版本使用4.1.1会报如下错误,需要把boot的版本降低

java 复制代码
Caused by: java.lang.IllegalStateException: @ConditionalOnMissingBean did not specify a bean using type, name or annotation and the attempt to deduce the bean's type failed
	at org.springframework.boot.autoconfigure.condition.OnBeanCondition$Spec.validate(OnBeanCondition.java:657) ~[spring-boot-autoconfigure-4.1.1.jar!/:4.1.1]
	at org.springframework.boot.autoconfigure.condition.OnBeanCondition$Spec.<init>(OnBeanCondition.java:603) ~[spring-boot-autoconfigure-4.1.1.jar!/:4.1.1]
	at org.springframework.boot.autoconfigure.condition.OnBeanCondition.getMatchOutcome(OnBeanCondition.java:147) ~[spring-boot-autoconfigure-4.1.1.jar!/:4.1.1]
	at org.springframework.boot.autoconfigure.condition.SpringBootCondition.matches(SpringBootCondition.java:47) ~[spring-boot-autoconfigure-4.1.1.jar!/:4.1.1]
	... 24 common frames omitted
Caused by: org.springframework.boot.autoconfigure.condition.OnBeanCondition$BeanTypeDeductionException: Failed to deduce bean type for org.springframework.cloud.client.discovery.simple.SimpleDiscoveryClientAutoConfiguration.simpleDiscoveryProperties
	at org.springframework.boot.autoconfigure.condition.OnBeanCondition$Spec.deducedBeanTypeForBeanMethod(OnBeanCondition.java:686) ~[spring-boot-autoconfigure-4.1.1.jar!/:4.1.1]
	at org.springframework.boot.autoconfigure.condition.OnBeanCondition$Spec.deducedBeanType(OnBeanCondition.java:676) ~[spring-boot-autoconfigure-4.1.1.jar!/:4.1.1]
	at org.springframework.boot.autoconfigure.condition.OnBeanCondition$Spec.<init>(OnBeanCondition.java:596) ~[spring-boot-autoconfigure-4.1.1.jar!/:4.1.1]
	... 26 common frames omitted
Caused by: java.lang.IllegalStateException: Failed to introspect Class [org.springframework.cloud.client.discovery.simple.SimpleDiscoveryClientAutoConfiguration] from ClassLoader [org.springframework.boot.loader.launch.LaunchedClassLoader@28a418fc]
	at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:483) ~[spring-core-7.0.9.jar!/:7.0.9]
	at org.springframework.util.ReflectionUtils.findMethod(ReflectionUtils.java:240) ~[spring-core-7.0.9.jar!/:7.0.9]
	at org.springframework.util.ReflectionUtils.findMethod(ReflectionUtils.java:221) ~[spring-core-7.0.9.jar!/:7.0.9]
	at org.springframework.boot.autoconfigure.condition.OnBeanCondition$Spec.findBeanMethod(OnBeanCondition.java:715) ~[spring-boot-autoconfigure-4.1.1.jar!/:4.1.1]
	at org.springframework.boot.autoconfigure.condition.OnBeanCondition$Spec.getMethodReturnType(OnBeanCondition.java:710) ~[spring-boot-autoconfigure-4.1.1.jar!/:4.1.1]
	at org.springframework.boot.autoconfigure.condition.OnBeanCondition$Spec.getReturnType(OnBeanCondition.java:694) ~[spring-boot-autoconfigure-4.1.1.jar!/:4.1.1]
	at org.springframework.boot.autoconfigure.condition.OnBeanCondition$Spec.deducedBeanTypeForBeanMethod(OnBeanCondition.java:683) ~[spring-boot-autoconfigure-4.1.1.jar!/:4.1.1]
	... 28 common frames omitted
Caused by: java.lang.NoClassDefFoundError: org/springframework/boot/autoconfigure/web/ServerProperties
	at java.base/java.lang.Class.getDeclaredMethods0(Native Method) ~[na:na]
	at java.base/java.lang.Class.privateGetDeclaredMethods(Class.java:3402) ~[na:na]
	at java.base/java.lang.Class.getDeclaredMethods(Class.java:2504) ~[na:na]
	at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:465) ~[spring-core-7.0.9.jar!/:7.0.9]
	... 34 common frames omitted
Caused by: java.lang.ClassNotFoundException: org.springframework.boot.autoconfigure.web.ServerProperties
	at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:440) ~[na:na]
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:587) ~[na:na]
	at org.springframework.boot.loader.net.protocol.jar.JarUrlClassLoader.loadClass(JarUrlClassLoader.java:107) ~[spring_demo_sentinel-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT]
	at org.springframework.boot.loader.launch.LaunchedClassLoader.loadClass(LaunchedClassLoader.java:91) ~[spring_demo_sentinel-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT]
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520) ~[na:na]
	... 38 common frames omitted

springboodt项目引入sentinel依赖

<!--sentinel-->

<dependency>

<groupId>com.alibaba.cloud</groupId>

<artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>

<version>2022.0.0.0-RC2</version>

</dependency>

springboot的版本使用 3.0.9

<parent>

<groupId>org.springframework.boot</groupId>

<artifactId>spring-boot-starter-parent</artifactId>

<!-- fixme 版本必须是 3.0.9 配合 spring alibaba的 2022.0.0.0-RC2版本 -->

<version>3.0.9</version>

</parent>

添加控制台配置

复制代码
spring:
  cloud:
    sentinel:
      transport:
        dashboard: localhost:8080  # 配置sentinel控制台地址

启动/部署项目后访问测试

http://8.160.170.126:8081/api/sentinel/hello

sentinel控制台可以看到实时监控了

http:8.160.170.126:8080/#/dashboard/metric/spring_demo_sentinel

相关推荐
Pniubi2 小时前
怎么排查慢SQL,怎么解决?
java·数据库·sql
薛之谦_3 小时前
Java 全栈知识体系:从 IDEA 高效开发到 JVM、并发与 Stream 实战
java·jvm·intellij-idea
文丑颜不良啊7 小时前
LeetCode2761~2780题目解析
java·leetcode
IT枫斗者枫哥8 小时前
子线程断言失败,JUnit 为什么还显示通过?
java·后端
考虑考虑10 小时前
JDK27中的Set.ofLazy
java·后端·java ee
文丑颜不良啊10 小时前
LeetCode2841~2860题目解析
java·leetcode
小南家的青蛙10 小时前
Tomcat与Jetty深度对比
java·tomcat·jetty
乌暮12 小时前
Spring AOP 与 Spring 事务:用大白话彻底理解原理与实践
java·数据库·spring boot·后端·sql·学习·spring
YDS82912 小时前
Small Spring IOC篇:容器事件及其监听器
java·spring
金銀銅鐵12 小时前
带您看懂字节码指令(三):一行加法里有什么
java·jvm