在没有类调解器的情况下在启动期间在WSO2 MI Serverr API中加载属性文件

Loading Property Files in WSO2 MI Serverr API during Startup without Class Mediator

提问人:Rocky 提问时间:11/3/2023 更新时间:11/6/2023 访问量:37

问:

我正在使用 WSO2 Micro Integrator (MI) Server,我有一组属性文件,我需要使用 get-property('propName') 等函数在 API 中访问这些文件。但是,我希望在服务器启动期间加载这些属性,而无需每次都使用类中介来加载文件和设置属性。

是否有特定于WSO2 MI Server的推荐方法或最佳实践来实现此目的?我正在寻找一种解决方案,允许在服务器启动期间加载一次属性。任何指导或建议将不胜感激。

标签: wso2 [wso2-micro-integrator], [api], [property-files], [class-mediator], [server-startup]

我需要使用 get-property('file','propertyName') 等 xpath 表达式在 API 中获取该属性

属性 WSO2-ESB WSO2-微积分器

评论


答:

0赞 ycr 11/3/2023 #1

Micro Integrator 支持 OOB。您可以将属性添加到名为的文件中,并将其放在目录中,它将被自动拾取。如果你有一个自定义属性文件,假设你可以在服务器启动时传递文件路径,如下所示,方法是将它添加到启动脚本中,以便加载它。file.properties<MI_HOME>/confcustom.properties

-Dproperties.file.path=/home/user/ei_configs/dev/custom.properties

加载文件后。您可以将属性读取为属性,如下所示。

<property name="someProp" expression="get-property('file','propName')" scope="default" />

在这里阅读更多内容

更新

由于可以传递多个文件,因此作为解决方法,您可以根据环境创建 shell 脚本或批处理脚本,以读取多个属性文件并将它们合并到单个文件中。您可以将此脚本添加到该脚本中,以便在服务器启动时执行该脚本。示例脚本打击。micro-integrator.sh

# Assume that the properties files are available the location you are executing the server startup script.

output_file="${CARBON_HOME}/conf/file.properties"

for properties_file in *.properties; do
    if [ -f "$properties_file" ]; then
        cat "$properties_file" >> "$output_file"
    fi
done

评论

0赞 Rocky 11/6/2023
对于一个属性文件来说,这是可以的,但我有可能属性文件如何加载它们。
0赞 ycr 11/6/2023
@Rocky检查更新后的答案。