From 19eadb0f780b859286098c4115cfcf8aaa37b742 Mon Sep 17 00:00:00 2001 From: Looly Date: Mon, 20 Mar 2023 23:14:04 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96SpringUtil=E5=9C=A8=E9=9D=9ES?= =?UTF-8?q?pring=E7=8E=AF=E5=A2=83=E4=B8=8B=E7=9A=84=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 3 ++- .../src/main/java/cn/hutool/extra/spring/SpringUtil.java | 6 +++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 485e6801e..4ae3607fa 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,12 +2,13 @@ # 🚀Changelog ------------------------------------------------------------------------------------------------------------- -# 5.8.16.M1 (2023-03-17) +# 5.8.16.M1 (2023-03-20) ### 🐣新特性 * 【core 】 改进Calculator.conversion,兼容乘法符号省略写法(issue#2964@Github) * 【core 】 改进XmlUtil.xmlToBean,支持xml转bean时父节点忽略大小写 * 【core 】 优化ArrayUtil的空判断(pr#2969@Github) +* 【extra 】 优化SpringUtil在非Spring环境下的异常(issue#2835@Github) ### 🐞Bug修复 * 【crypto】 修复NoSuchMethodError未捕获问题(issue#2966@Github) diff --git a/hutool-extra/src/main/java/cn/hutool/extra/spring/SpringUtil.java b/hutool-extra/src/main/java/cn/hutool/extra/spring/SpringUtil.java index ea08f0921..203888014 100755 --- a/hutool-extra/src/main/java/cn/hutool/extra/spring/SpringUtil.java +++ b/hutool-extra/src/main/java/cn/hutool/extra/spring/SpringUtil.java @@ -71,7 +71,11 @@ public class SpringUtil implements BeanFactoryPostProcessor, ApplicationContextA * @since 5.7.0 */ public static ListableBeanFactory getBeanFactory() { - return null == beanFactory ? applicationContext : beanFactory; + final ListableBeanFactory factory = null == beanFactory ? applicationContext : beanFactory; + if(null == factory){ + throw new UtilException("No ConfigurableListableBeanFactory or ApplicationContext injected, maybe not in the Spring environment?"); + } + return factory; } /**