mirror of
https://gitee.com/dromara/hutool.git
synced 2025-04-05 17:37:59 +08:00
add methods
This commit is contained in:
parent
a0a3e4905f
commit
c3cc8381ab
@ -3,7 +3,7 @@
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------
|
||||
|
||||
## 5.3.3 (2020-04-25)
|
||||
## 5.3.3 (2020-04-29)
|
||||
|
||||
### 新特性
|
||||
* 【core 】 ImgUtil.createImage支持背景透明(issue#851@Github)
|
||||
@ -11,6 +11,7 @@
|
||||
* 【cron 】 表达式的所有段支持L关键字(issue#849@Github)
|
||||
* 【extra 】 增加PinyinUtil,封装TinyPinyin
|
||||
* 【extra 】 Ftp和Sftp增加FtpConfig,提供超时等更多可选参数
|
||||
* 【extra 】 SpringUtil增加getActiveProfiles、getBeansOfType、getBeanNamesForType方法(issue#I1FXF3@Gitee)
|
||||
|
||||
### Bug修复
|
||||
* 【core 】 修复URLBuilder中请求参数有`&`导致的问题(issue#850@Github)
|
||||
|
@ -1,9 +1,12 @@
|
||||
package cn.hutool.extra.spring;
|
||||
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ApplicationContextAware;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Spring(Spring boot)工具封装,包括:
|
||||
*
|
||||
@ -70,6 +73,58 @@ public class SpringUtil implements ApplicationContextAware {
|
||||
return applicationContext.getBean(name, clazz);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定类型对应的所有Bean,包括子类
|
||||
*
|
||||
* @param <T> Bean类型
|
||||
* @param type 类、接口,null表示获取所有bean
|
||||
* @return 类型对应的bean,key是bean注册的name,value是Bean
|
||||
* @since 5.3.3
|
||||
*/
|
||||
public static <T> Map<String, T> getBeansOfType(Class<T> type){
|
||||
return applicationContext.getBeansOfType(type);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定类型对应的Bean名称,包括子类
|
||||
* @param type 类、接口,null表示获取所有bean名称
|
||||
* @return bean名称
|
||||
* @since 5.3.3
|
||||
*/
|
||||
public static String[] getBeanNamesForType(Class<?> type){
|
||||
return applicationContext.getBeanNamesForType(type);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取配置文件配置项的值
|
||||
*
|
||||
* @param key 配置项key
|
||||
* @since 5.3.3
|
||||
*/
|
||||
public static String getProperty(String key) {
|
||||
return applicationContext.getEnvironment().getProperty(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前的环境配置,无配置返回null
|
||||
*
|
||||
* @return 当前的环境配置
|
||||
* @since 5.3.3
|
||||
*/
|
||||
public static String[] getActiveProfiles(){
|
||||
return applicationContext.getEnvironment().getActiveProfiles();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前的环境配置,当有多个环境配置时,只获取第一个
|
||||
*
|
||||
* @return 当前的环境配置
|
||||
* @since 5.3.3
|
||||
*/
|
||||
public static String getActiveProfile(){
|
||||
final String[] activeProfiles = getActiveProfiles();
|
||||
return ArrayUtil.isNotEmpty(activeProfiles) ? activeProfiles[0] : null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user