我在Ubuntu服务器SDB_DOMAIN
上有一个环境变量,我正试图传递给这个gradle属性文件:
https://github.com/Netflix/SimianArmy/blob/master/src/main/resources/janitor.properties#L20
将环境变量拉入这样的属性文件的语法是什么?我尝试了几种不同的方法,例如:simianarmy.janitor.snapshots.ownerId = System.getenv("SIMIAN_OWNER_ID")
但是当我使用gradlew jettRun
启动jetty服务器时,它只返回文字值并观察日志。
19:55:53.957 [main] INFO c.n.s.basic.BasicSimianArmyContext - using standard class for simianarmy.client.recorder.class
19:55:54.060 [main] INFO c.n.simianarmy.aws.SimpleDBRecorder - Creating SimpleDB domain: "System.getenv(SDB_DOMAIN)"
19:55:54.122 [main] WARN c.n.simianarmy.aws.SimpleDBRecorder - Error while trying to auto-create SimpleDB domain
com.amazonaws.services.simpledb.model.InvalidParameterValueException: Value ("System.getenv(SDB_DOMAIN)") for parameter DomainName is invalid. (Service: AmazonSimpleDB; Status Code: 400; Error Code: InvalidParameterValue; Request ID: 4aabdeb2-68a5-0f49-dacd-17c96f375793)
答案 0 :(得分:2)
这就是我所做的。我想要我的Spring-Boot应用程序向我展示$ HOME变量。
我的 application.properties 文件:
variable.home = #{ systemEnvironment['HOME'] }
正在使用它的类:
@Component
public class SomeName implements CommandLineRunner {
@Value("${variable.home}" )
String home;
@Override
public void run(String... args) throws Exception {
System.out.println(home);
}
public String getHome() {
return home;
}
public void setHome(String home) {
this.home = home;
}
}
Spring启动日志:
2015-12-10 17:46:07.622 INFO 5710 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
2015-12-10 17:46:07.652 INFO 5710 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8080 (http)
/home/dogbert
2015-12-10 17:46:07.655 INFO 5710 --- [ main] com.example.DemoApplication : Started DemoApplication in 1.431 seconds (JVM running for 1.614)
和 echo $ HOME :
dogbert@borsuk:~$ echo $HOME
/home/dogbert
dogbert@borsuk:~$
我希望这会有所帮助。