mirror of
https://gitee.com/dromara/hutool.git
synced 2025-04-05 17:20:07 +08:00
SpringUtil增加getProperty重载
This commit is contained in:
parent
3c68b2b7b1
commit
9866840b81
@ -9,6 +9,7 @@
|
||||
* 【cache 】 JWT#sign增加重载,可选是否增加默认的typ参数(issue#3386@Github)
|
||||
* 【db 】 增加识别OpenGauss的驱动类(issue#I8K6C0@Gitee)
|
||||
* 【core 】 修复CharSequenceUtil注释和引用,避免循环引用
|
||||
* 【extra 】 SpringUtil增加getProperty重载(pr#1122@Gitee)
|
||||
|
||||
### 🐞Bug修复
|
||||
* 【core 】 修复LocalDateTime#parseDate未判断空问题问题(issue#I8FN7F@Gitee)
|
||||
|
@ -71,8 +71,8 @@ public class SpringUtil implements BeanFactoryPostProcessor, ApplicationContextA
|
||||
* @since 5.7.0
|
||||
*/
|
||||
public static ListableBeanFactory getBeanFactory() {
|
||||
final ListableBeanFactory factory = null == beanFactory ? applicationContext : beanFactory;
|
||||
if(null == factory){
|
||||
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;
|
||||
@ -182,26 +182,33 @@ public class SpringUtil implements BeanFactoryPostProcessor, ApplicationContextA
|
||||
* @since 5.3.3
|
||||
*/
|
||||
public static String getProperty(String key) {
|
||||
return getProperty(key, null);
|
||||
if (null == applicationContext) {
|
||||
return null;
|
||||
}
|
||||
return applicationContext.getEnvironment().getProperty(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取配置文件配置项的值
|
||||
*
|
||||
* @param key 配置项key
|
||||
* @param key 配置项key
|
||||
* @param defaultValue 默认值
|
||||
* @return 属性值
|
||||
* @since 5.8.24
|
||||
*/
|
||||
public static String getProperty(String key, String defaultValue) {
|
||||
return getProperty(key, String.class, defaultValue);
|
||||
if (null == applicationContext) {
|
||||
return null;
|
||||
}
|
||||
return applicationContext.getEnvironment().getProperty(key, defaultValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取配置文件配置项的值
|
||||
*
|
||||
* @param key 配置项key
|
||||
* @param targetType 配置项类型
|
||||
* @param <T> 属性值类型
|
||||
* @param key 配置项key
|
||||
* @param targetType 配置项类型
|
||||
* @param defaultValue 默认值
|
||||
* @return 属性值
|
||||
* @since 5.8.24
|
||||
|
Loading…
Reference in New Issue
Block a user