1

我正在使用没有任何弹簧依赖项的 Guice。

有没有办法将系统属性传递给 Module.java (java -Dfoo="asda") 目标是从 jar 文件外部加载属性。

到目前为止,大多数示例都使用预先存在的属性文件

类似于这个问题: Guice properties injection

4

2 回答 2

2

利用Names.bindProperties()

使用非常简单:

@Override protected void configure() {
  Names.bindProperties(binder(), System.getProperties());
}

然后每次注入时,@Named("java.user.home") String您都会获得System.getProperty("java.user.home").

于 2021-08-17T12:39:16.390 回答
0

使用 System.getProperty() 作为临时解决方案。但希望有更优雅的方式

于 2021-08-17T03:58:25.010 回答