赞
踩
新建了一个spring cloud项目,简单引入网关的依赖包,结果项目启动报错,信息如下:
Exception in thread "main" java.lang.IllegalArgumentException: Cannot instantiate interface org.springframework.boot.BootstrapRegistryInitializer : org.springframework.cloud.bootstrap.RefreshBootstrapRegistryInitializer at org.springframework.boot.SpringApplication.createSpringFactoriesInstances(SpringApplication.java:475) at org.springframework.boot.SpringApplication.getSpringFactoriesInstances(SpringApplication.java:457) at org.springframework.boot.SpringApplication.getSpringFactoriesInstances(SpringApplication.java:450) at org.springframework.boot.SpringApplication.getBootstrapRegistryInitializersFromSpringFactories(SpringApplication.java:297) at org.springframework.boot.SpringApplication.<init>(SpringApplication.java:285) at org.springframework.boot.SpringApplication.<init>(SpringApplication.java:266) at org.springframework.boot.SpringApplication.run(SpringApplication.java:1343) at org.springframework.boot.SpringApplication.run(SpringApplication.java:1332) at com.example.gatewaydemo.GatewayDemoApplication.main(GatewayDemoApplication.java:10) Caused by: java.lang.UnsupportedClassVersionError: org/springframework/cloud/bootstrap/RefreshBootstrapRegistryInitializer has been compiled by a more recent version of the Java Runtime (class file version 61.0), this version of the Java Runtime only recognizes class file versions up to 52.0 at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClass(ClassLoader.java:763) at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142) at java.net.URLClassLoader.defineClass(URLClassLoader.java:467) at java.net.URLClassLoader.access$100(URLClassLoader.java:73) at java.net.URLClassLoader$1.run(URLClassLoader.java:368) at java.net.URLClassLoader$1.run(URLClassLoader.java:362) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:361) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:338) at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
查看了网上博客,都说jdk的版本问题,检查完idea的jdk设置和pom文件的jdk版本设置,都没发现问题。
最后发现的问题是spring cloud的版本和springboot版本没对应
。
修改前pom文件如下:
springboot版本用的是2.5.5
spring cloud版本用的是2022.0.1
查看官网:https://spring.io/projects/spring-cloud
决定降低spring cloud的版本,修改后pom文件如下:
项目成功启动
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。