Solon v3.1.0

SolonProps 接口参考

</> markdown

SolonProps 是 Solon 应用的属性集合(或,配置中心)。实例使用方式:Solon.cfg(),例:

Solon.cfg().appName();

Solon.cfg().loadAdd("classpath:demo.yml");

1、SolonProps 主要接口或属性(扩展自 Props)

接口或属性说明
argx()获取启动参数集合
env()获取 solon.env 环境配置
appName()获取 solon.app.name 应用名配置
appGroup()获取 solon.app.group 应用分组配置
appNamespace()获取 solon.app.namespace 应用命名空间配置
appTitle()获取 solon.app.title 应用标题配置
appLicence()获取 solon.app.licence 应用许可证配置(商业版相关配置)
appEnabled()获取 solon.app.enabled 应用健康状况(是否启用)
serverPort()获取 server.port 服务端口配置值
serverHost()获取 server.host 服务主机配置值
serverWrapPort(boolean useRaw)获取 server.wrapPort 服务包装端口配置值
serverWrapHost(boolean useRaw)获取 server.wrapHost 服务包装主机配置值
serverContextPath()获取 server.contextPath 服务主上下文路径
serverContextPath(String path)手动设置 serverContextPath
serverContextPathForced()获取服务主上下文路径强制策略
loadEnv(String keyStarts)根据key前缀,加载环即变量 System.getenv() 到应用属性
loadEnv(Predicate<String> condition)根据检测条件,加载环即变量 System.getenv() 到应用属性
loadAdd(Properties props)加载属性(用于扩展加载)
loadAdd(Properties props)加载属性(用于扩展加载)
loadAdd(Properties props)加载属性(用于扩展加载)
plugs()获取插件配置集合
locale()获取 solon.locale 本地化配置
extend()获取 solon.extend 扩展目录配置(E-SPI 相关配置)
extendFilter()获取 solon.extendFilter 扩展目录过滤配置(E-SPI 相关配置)
testing()获取是否为单测时
isDebugMode()是否为调试模式运行
isSetupMode()是否为安装模式运行
isFilesMode()是否为文件运行模式(否则为包执行模式)
isDriftMode()是否为漂移模式(solon cloud 相关配置)
isWhiteMode()是否为白名单模式运行(solon 安全相关配置)
stopSafe()获取 solon.stop.safe 安全停止模式配置
stopDelay()获取 solon.stop.delay 安全停止延时配置
isEnabledVirtualThreads()获取 solon.threads.virtual.enabled 虚拟线程启用配置

2、Props 主要接口或属性(扩展自 Properties)

接口或属性说明
get(String key)获取属性(简写模式)
get(String key, String def)获取属性或默认值(简写模式)
getBool(String key, boolean def)获取布尔属性(简写模式)
getInt(String key, int def)获取整型属性或默认值(简写模式)
getLong(String key, long def)获取长整型属性或默认值(简写模式)
getDouble(String key, double def)获取双精度型属性或默认值(简写模式)
addAll(Properties data)添加属性集合
addAll(Map<String, String> data)添加属性集合
addAll(Iterable<KeyValues<String>> data)添加属性集合
loadAdd(String uri)加载属性文件
loadAdd(URL url)加载属性文件
loadAdd(Properties props)加载属性文件
loadAdd(Import anno)加载属性文件
loadAddIfAbsent(String uri)增量加载属性文件
loadAddIfAbsent(URL url)增量加载属性文件
loadAddIfAbsent(Properties props)增量加载加载属性文件
getProp(String keyStarts)->Props查找 keyStarts 开头的所有配置;并生成一个新的 配置集
getGroupedProp(String keyStarts)->Map<String, Props>查找 keyStarts 开头的所有配置;并生成一个新的分组配置集
getListedProp(String keyStarts)->Map<String, Props>查找 keyStarts 开头的所有配置;并生成一个新的列表配置集
toBean(String keyStarts, Class<T> clz)将相同前缀的属性转为 bean
toBean(Class<T> clz)将当前属性转为 bean
bindTo(Object bean)将当前属性绑定到一个 bean 实例上
getByKeys(String... keys)获取第一个非空的属性(尝试用多个key)
getByExpr(String expr)获取属性表达式值(${key} or key or ${key:def} or key:def
getByTmpl(String tmpl)获取属性模板值(${key} 或 aaa${key}bbb 或 ${key:def}/ccc