升级高版本springboot2.6.x:org/springframework/boot/context/properties/ConfigurationBeanFactoryMetadata
升级springboot高版本2.6.x
项目使用到了springcloud的oauth2依赖,直接升级springboot项目版本为最新 2.6.8(2022年6月16日)将会报以下错误: org/springframework/boot/context/properties/ConfigurationBeanFactoryMetadata
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'configurationPropertiesBeans' defined in class path resource [org/springframework/cloud/autoconfigure/ConfigurationPropertiesRebinderAutoConfiguration.class]: Post-processing of merged bean definition failed; nested exception is java.lang.IllegalStateException: Failed to introspect Class [org.springframework.cloud.context.properties.ConfigurationPropertiesBeans] from ClassLoader [sun.misc.Launcher$AppClassLoader@18b4aac2]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:597) ~[spring-beans-5.3.20.jar:5.3.20]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542) ~[spring-beans-5.3.20.jar:5.3.20]
Caused by: java.lang.IllegalStateException: Failed to introspect Class [org.springframework.cloud.context.properties.ConfigurationPropertiesBeans] from ClassLoader [sun.misc.Launcher$AppClassLoader@18b4aac2]
at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:485) ~[spring-core-5.3.20.jar:5.3.20]
at org.springframework.util.ReflectionUtils.doWithLocalMethods(ReflectionUtils.java:321) ~[spring-core-5.3.20.jar:5.3.20]
Caused by: java.lang.NoClassDefFoundError: org/springframework/boot/context/properties/ConfigurationBeanFactoryMetadata
at java.lang.Class.getDeclaredMethods0(Native Method) ~[na:1.8.0_202]
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701) ~[na:1.8.0_202]
at java.lang.Class.getDeclaredMethods(Class.java:1975) ~[na:1.8.0_202]
at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:467) ~[spring-core-5.3.20.jar:5.3.20]
... 36 common frames omitted
Caused by: java.lang.ClassNotFoundException: org.springframework.boot.context.properties.ConfigurationBeanFactoryMetadata
at java.net.URLClassLoader.findClass(URLClassLoader.java:382) ~[na:1.8.0_202]
at java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[na:1.8.0_202]
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349) ~[na:1.8.0_202]
at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[na:1.8.0_202]
... 40 common frames omitted
原因
springcloud下的oauth2依赖早已停止维护,而且最新的oauth2版本不支持高版本springboot,高版本中缺少该类。我们手动创建一个即可:
package org.springframework.boot.context.properties;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.GenericBeanDefinition;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.annotation.AnnotationUtils;
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;
/**
* @author lingkang
* Created by 2022/6/16
*
* 此类是为了兼容高版本与springcloud低版本依赖报错问题
* springcloud中的oauth2依赖不能使用2.4.x以上版本,但springcloud的oauth2已经停止维护了
* 需要在 配置文件中关闭检查:spring.cloud.compatibility-verifier.enabled=false
*
* - Change Spring Boot version to one of the following versions [2.2.x, 2.3.x] .
* You can find the latest Spring Boot versions here [https://spring.io/projects/spring-boot#learn].
* If you want to learn more about the Spring Cloud Release train compatibility, you can visit this page [https://spring.io/projects/spring-cloud#overview] and check the [Release Trains] section.
* If you want to disable this check, just set the property [spring.cloud.compatibility-verifier.enabled=false]
*/
public class ConfigurationBeanFactoryMetadata implements ApplicationContextAware {
public static final String BEAN_NAME = ConfigurationBeanFactoryMetadata.class.getName();
private ConfigurableApplicationContext applicationContext;
public ConfigurationBeanFactoryMetadata() {
}
public <A extends Annotation> Map<String, Object> getBeansWithFactoryAnnotation(Class<A> type) {
Map<String, Object> result = new HashMap();
String[] var3 = this.applicationContext.getBeanFactory().getBeanDefinitionNames();
int var4 = var3.length;
for (int var5 = 0; var5 < var4; ++var5) {
String name = var3[var5];
if (this.findFactoryAnnotation(name, type) != null) {
result.put(name, this.applicationContext.getBean(name));
}
}
return result;
}
public <A extends Annotation> A findFactoryAnnotation(String beanName, Class<A> type) {
Method method = this.findFactoryMethod(beanName);
return method != null ? AnnotationUtils.findAnnotation(method, type) : null;
}
public Method findFactoryMethod(String beanName) {
ConfigurableListableBeanFactory beanFactory = this.applicationContext.getBeanFactory();
if (beanFactory.containsBeanDefinition(beanName)) {
BeanDefinition beanDefinition = beanFactory.getMergedBeanDefinition(beanName);
if (beanDefinition instanceof RootBeanDefinition) {
return ((RootBeanDefinition) beanDefinition).getResolvedFactoryMethod();
}
}
return null;
}
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
this.applicationContext = (ConfigurableApplicationContext) applicationContext;
}
static void register(BeanDefinitionRegistry registry) {
if (!registry.containsBeanDefinition(BEAN_NAME)) {
GenericBeanDefinition definition = new GenericBeanDefinition();
definition.setBeanClass(ConfigurationBeanFactoryMetadata.class);
definition.setRole(2);
registry.registerBeanDefinition(BEAN_NAME, definition);
}
}
}
升级高版本springboot2.6.x:org/springframework/boot/context/properties/ConfigurationBeanFactoryMetadata的更多相关文章
- SpringBoot整合nacos启动报错:java.lang.NoClassDefFoundError: org/springframework/boot/context/properties/ConfigurationBeanFactoryMetadata
报错信息 org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'nacosCo ...
- spring boot之org.springframework.boot.context.TypeExcludeFilter
曾经碰到过这样一种情况,想让某个使用了spring 注解的类不被spring扫描注入到spring bean池中,比如下面的类使用了@Component和@ConfigurationPropertie ...
- java.lang.NoClassDefFoundError: org/springframework/boot/context/embedded/FilterRegistrationBean
昨天还好好的, 今天我的spring boot 项目就不能正常运行了! 出现: 018-07-06 10:01:41.776 WARN [mq-service,,,] 7 --- [ main] at ...
- 构建eureka-server异常ClassNotFoundException: org.springframework.boot.context.embedded.FilterRegistrationBean
Caused by: java.lang.ClassNotFoundException: org.springframework.boot.context.embedded.FilterRegistr ...
- java.lang.ClassNotFoundException: org.springframework.boot.context.embedded.FilterRegistrationBean
java.lang.ClassNotFoundException: org.springframework.boot.context.embedded.FilterRegistrationBean 把 ...
- Caused by: java.lang.ClassNotFoundException: org.springframework.boot.context.embedded.FilterRegistrationBean
Caused by: java.lang.ClassNotFoundException: org.springframework.boot.context.embedded.FilterRegistr ...
- Exception in thread "main" java.lang.AbstractMethodError: org.springframework.boot.context.config.ConfigFileApplicationListener.supportsSourceType(Ljava/lang/Class;)Z
依赖冲突,查看pom.xml文件 查看parent项目的依赖版本为 <parent> <groupId>org.springframework.boot</groupId ...
- Exception in thread "main" java.lang.NoClassDefFoundError: org/springframework/boot/context/embedded/ServletRegistrationBean
异常信息 2017-09-02 18:06:37.223 [main] ERROR o.s.boot.SpringApplication - Application startup failed ja ...
- SpringBoot项目 org.springframework.boot.context.embedded.EmbeddedServletContainerException: Unable to start embedded Jetty servlet container报错
SpringBoot项目启动报错 ERROR 2172 --- [ main] o.s.boot.SpringApplication : Application startup failed org. ...
- Centos下给PHP一键升级高版本7.2.0
我是在Centos下测试的,目前php版本是7.0.0,我要升级到php7.2.0,下面开始. 执行命令 # wget http://soft.vpser.net/lnmp/upgrade_php.s ...
随机推荐
- fepk文件格式说明
1 卫星影像金字塔分块原理说明 通常我们在工作中使用的卫星影像数据,轻则几百M,重则几百个G甚至上TB级.影像数据太大,是大家经常会遇到的一个问题,尤其是想下载一个省以上数据的时候该问题尤为突出.那 ...
- Java虚拟机(JVM):第一幕:起源,不一定全,但是一定靠谱
在学习JVM之前,先分享一则信息:2009 年4月20日,Orace 宣布正式以74 亿美元的价格收购市值曾超过2000 亿美元的Sun公司,传奇的Sun Microsystems 从此落幕成为历史. ...
- P8679 [蓝桥杯 2019 省 B] 填空问题 题解
P8679 [蓝桥杯 2019 省 B] 填空问题 题解 题目传送门 欢迎大家指出错误并联系这个蒟蒻 更新日志 2023-05-25 21:02 文章完成 2023-05-27 11:34 文章通过审 ...
- OpenResty入门之压测篇:压测工具界的 “悍马” wrk 审核中
在上篇文章 每个后端都应该了解的 OpenResty 入门以及网关安全实战 中,我向大家介绍了 OpenResty 的入门使用是 WAF 防御实战,这篇文章将给大家继续介绍 OpenResty 入门之 ...
- C#.NET 国密SM4 CBC 对称加解密 与JAVA互通 ver:20231103
C#.NET 国密SM4 CBC 对称加解密 与JAVA互通 ver:20231103 .NET 环境:.NET6 控制台程序(.net core). JAVA 环境:JAVA8,带maven 的JA ...
- GitHub - 如何对开源项目做出贡献
GitHub - 对项目做出贡献 转载来自git官方教程:https://git-scm.com/book/zh/v2/GitHub-对项目做出贡献 对项目做出贡献 账户已经建立好了,现在我们来了解一 ...
- Excel 数据处理
博客地址:https://www.cnblogs.com/zylyehuo/ 2023 年高教社杯全国大学生数学建模竞赛题目 -- B 题 多波束测线问题 图表格式 import numpy as n ...
- ics-06
打开题目界面有点科技感,然后找到报表中心的位置 url地方出现了一个奇怪的id,试了下sql注入但是没报错,判断应该不是sql注入,然后就坐牢了 看了wp得在id的地方进行爆破 爆破了1-2500可以 ...
- HTML基础_01
HTML 基础_01 01.初识 HTML 什么是 HTML! Hyper Text Markup Language(超文本标记语言).超文本包括文字.图片.音频.视频.动画等. HTML5,提供了一 ...
- Static关键词
在程序中使用static 变量 1. 局部变量 普通局部变量是再熟悉不过的变量了,在任何一个函数内部定义的变量(不加static修饰符)都属于这个范畴.编译器一般不对普通局部变量进行初始化,也就是说它 ...