import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;
import java.util.Locale;
@Component
public class SpringContextUtil implements ApplicationContextAware {
private static ApplicationContext context = null;
/* (non Javadoc)
* @Title: setApplicationContext
* @Description: spring获取bean工具类
* @param applicationContext
* @throws BeansException
* @see org.springframework.context.ApplicationContextAware#setApplicationContext(org.springframework.context.ApplicationContext)
*/
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
context = applicationContext;
}
// 传入线程中
public static <T> T getBean(String beanName) {
return (T) context.ge
springboot获取当前运行环境
最新推荐文章于 2024-07-16 09:00:00 发布
本文介绍了如何在Spring Boot中设置和获取当前运行环境。通过在配置文件中添加spring.profiles.active来指定环境,例如dev、pre或pd。在Spring Boot 2.5.2版本中,本地IDEA开发环境下,需要在VM options中进行特定配置,而在2.2.7版本则不需要,可以直接读取环境信息。
摘要由CSDN通过智能技术生成