Huang Xuyang

Results 34 comments of Huang Xuyang

同一个文件吗?完整的堆栈截图发一下看看

需要读取给定的配置文件吗?电脑的信息放在配置文件里,如 xx.properties 文件,然后里的 module 去加载这个配置文件,是这个意思吗?

我之前就是为了这个需求,fork 了分支改源码 https://github.com/dadiyang/jvm-sandbox 让框架支持在启动的时候自定义一些启动参数。并且提交了 PR:https://github.com/alibaba/jvm-sandbox/pull/163 但是作者在交流群里一直跟我说过几天合,月末合,然后两个月过去了。还是没接收。 如果你有这个需求,建议到群里圈一下群主,让他合并一个我的 PR。

可以获取到启动的自定义参数,我们就可以在启动的时候指定一个配置文件路径,然后在 module 里根据指定的路径去读取配置文件了。

让 sandbox 传配置文件流?那它从哪里找你自定义的配置文件呢?你总得告诉它,你的配置是什么,它才能给你传啊。

配置中心,这个有很多种实现方式,这个就不适合让 sandbox 来提供了,毕竟它不是干这个使的。

我的分支就支持获取 sandbox.properties 中的配置项。具体查看:[CoreConfigure.java](https://github.com/dadiyang/jvm-sandbox/blob/master/sandbox-core/src/main/java/com/alibaba/jvm/sandbox/core/CoreConfigure.java) 的getProperty方法。由于在[AgentLauncher.java](https://github.com/dadiyang/jvm-sandbox/blob/master/sandbox-agent/src/main/java/com/alibaba/jvm/sandbox/agent/AgentLauncher.java) 的第 236 行调用了CoreConfigure.toConfigure 方法,这个方法把从 sandbox.properties 文件读取到的配置项跟 Agent 参数传递的配置项合并到了CoreConfigure 的 featureMap。而我添加的 CoreConfigure.getProperty 方法就是提供从 CoreConfigure 的 featureMap 中读取配置项的方法。

在 Module 中直接使用 @Resource 注入就可以了 ```java @Resource private ConfigInfo configInfo; ```

依赖注入是在 com.alibaba.jvm.sandbox.core.manager.impl.DefaultCoreModuleManager.injectResourceOnLoadIfNecessary 做的。 配置文件在 CoreConfigure.fetchProperties 方法读取完就关闭流了: ```java // 从指定配置文件路径中获取配置信息 private static Properties fetchProperties(final String propertiesFilePath) { final Properties properties = new Properties(); InputStream is = null; try { is =...

我写的几个都是新注册的模块,并且使用 http 服务通信的例子。不用配置 META-INF,通过添加注解即可。 ```java @MetaInfServices(Module.class) @Information(id = "call-chain", author = "dadiyang", version = "0.0.1") public class CallChainModule implements Module{} ```