java服务器读取配置文件
来源:互联网 发布:酷优网络 编辑:程序博客网 时间:2024/06/05 23:43
切换配置文件,完成参数切换。
1.编辑POM
<dependencies> <!-- property configuration --> <dependency> <groupId>commons-configuration</groupId> <artifactId>commons-configuration</artifactId> <version>1.10</version> </dependency> </dependencies> <properties> <!-- Disable Swagger by default --> <swagger.enabled>false</swagger.enabled> </properties> <profiles> <profile> <id>localTest</id> <properties> <swagger.enabled>true</swagger.enabled> </properties> </profile> </profiles>
这样配置文件为localTest时开启swagger
2.在resources下新建文件TestConfig.properties
编辑TestConfig.properties
#swagger stateswagger.enabled = ${swagger.enabled}
3.调用
import org.apache.commons.configuration.Configuration;import org.apache.commons.configuration.ConfigurationException;import org.apache.commons.configuration.PropertiesConfiguration;//swagger try { Configuration config = new PropertiesConfiguration("TestConfig.properties"); if(config.getBoolean("swagger.enabled")){ buildSwagger(); handlerList.addHandler(buildSwaggerUI()); } } catch (ConfigurationException e) { }
这样当配置文件为localTest时,swagger开启,否则关闭
阅读全文
0 0
- java服务器读取配置文件
- java中读取服务器配置文件方法
- java读取配置文件
- java读取配置文件
- java 读取properties配置文件
- Java读取properties配置文件
- JAVA读取配置文件路径
- java读取xml配置文件
- JAVA读取配置文件
- Java读取配置文件
- Java配置文件读取
- java读取xml配置文件
- java读取properties配置文件
- java 读取配置文件properties
- java读取配置文件
- Java读取配置文件
- java读取配置文件
- java读取配置文件property
- Callable与Future
- windows查看端口占用以及关闭相应的进程
- Oracle 存储过程之增删改查
- ES6之Generator
- Android中UI线程与后台线程交互设计的5种方法
- java服务器读取配置文件
- jdk9更新导致eclipse无法启动
- MySQL/Mariadb基准测试工具-tpcc-mysql和sysbench区别
- jQuery取得select选择的文本与值
- 经典的 Java main方法面试题
- Date格式的时间,后面有个.0的处理方式
- 推箱子一步判断(四个方向都有)
- Redis数据库入门
- 为客户之旅开发内容