从配置文件中初始化spring profile
来源:互联网 发布:java转义代码 编辑:程序博客网 时间:2024/06/10 22:19
config.properties
profile=tomcat
重写org.springframework.web.context.ContextLoaderListener的customizeContext方法
public class ContextLoaderListener extends org.springframework.web.context.ContextLoaderListener {@Overrideprotected void customizeContext(ServletContext sc, ConfigurableWebApplicationContext wac) {Resource resource = new ClassPathResource("config.properties");Properties properties = new Properties();try {properties.load(resource.getInputStream());} catch (IOException e) {throw new RuntimeException("加载配置文件config.properties失败", e);}String profile = properties.getProperty("profile");if (StringUtils.isBlank(profile)) {profile = "dev";}wac.getEnvironment().setActiveProfiles(profile);super.customizeContext(sc, wac);}}
web.xml
<listener> <listener-class>com.xxx.ContextLoaderListener</listener-class> </listener>
代码中使用
@Profile("dev") @Configuration public class DevConfig { ...... }
0 0
- 从配置文件中初始化spring profile
- 从配置文件中取得初始化参数
- spring使用profile选择配置文件
- [linux]mac profile配置文件初始化与设置
- spring工具-- 配置文件初始化.
- spring初始化配置文件
- 初始化spring配置文件
- spring profile多配置文件的切换
- Spring PropertyPlaceholderConfigurer初始化properties配置文件
- bash中profile等配置文件执行顺序
- bash中profile等配置文件执行顺序
- 从spring配置文件中读取bean的方法
- Spring从配置文件中读取中文,显示乱码
- Spring Boot学习--从配置文件中获取随机数
- spring源码解析-从xml配置文件中获取bean
- 监听tomcat服务器启动/关闭并从配置文件中读取参数进行初始化
- spring从文件系统载入配置文件
- Spring从配置文件注入变量
- 如何查看android data 内容
- ajax参数详解
- 过滤器
- android高仿微信UI点击头像显示大图片效果
- 初识Hadoop's Ecosystem
- 从配置文件中初始化spring profile
- 实现DUBBO服务环境隔离
- iOS OC笔试题、swift、OC
- C++学习笔记-关联容器
- Adb
- INSTALL_FAILED_UPDATE_INCOMPATIBLE
- 流形式下载文件(结合POI生成excel使用)
- hdu1151Air Raid——最小路径覆盖
- SOUI的SMessage函数使用