优化SpringUtil在非Spring环境下的异常

This commit is contained in:
Looly
2023-03-20 23:14:04 +08:00
parent 23b74ed7bf
commit 19eadb0f78
2 changed files with 7 additions and 2 deletions

View File

@@ -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;
}
/**