From fb1b82889828d7cfdd7b8378736a87b1340bb3c9 Mon Sep 17 00:00:00 2001 From: Charles7c Date: Mon, 4 Dec 2023 21:56:03 +0800 Subject: [PATCH] =?UTF-8?q?SpringUtil=E5=A2=9E=E5=8A=A0getProperty?= =?UTF-8?q?=E9=87=8D=E8=BD=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cn/hutool/extra/spring/SpringUtil.java | 27 ++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) 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 203888014..f8219f8d1 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 @@ -182,10 +182,35 @@ public class SpringUtil implements BeanFactoryPostProcessor, ApplicationContextA * @since 5.3.3 */ public static String getProperty(String key) { + return getProperty(key, null); + } + + /** + * 获取配置文件配置项的值 + * + * @param key 配置项key + * @param defaultValue 默认值 + * @return 属性值 + * @since 5.8.24 + */ + public static String getProperty(String key, String defaultValue) { + return getProperty(key, String.class, defaultValue); + } + + /** + * 获取配置文件配置项的值 + * + * @param key 配置项key + * @param targetType 配置项类型 + * @param defaultValue 默认值 + * @return 属性值 + * @since 5.8.24 + */ + public static T getProperty(String key, Class targetType, T defaultValue) { if (null == applicationContext) { return null; } - return applicationContext.getEnvironment().getProperty(key); + return applicationContext.getEnvironment().getProperty(key, targetType, defaultValue); } /**