0

In local environment , we can configure some connection Environment properties in a property file, and then use them by context:property-placeholder. for example:

<context:property-placeholder location="classpath:resources-local.properties"/>
<smtp:endpoint host="${smtp.host}" port="${smtp.port}" user="${smtp.user}"            password="${smtp.password}" name="NotificationEmail" doc:name="SMTP" to="${smtp.to}"        from="${smtp.from}" subject="error" />

But when I deploy the app to cloudhub,I can set the connection info as Environment variables.We don't need to import the resources-local.properties file.We can still use the properties as

<smtp:endpoint host="${smtp.host}" port="${smtp.port}" user="${smtp.user}"            password="${smtp.password}" name="NotificationEmail" doc:name="SMTP" to="${smtp.to}"        from="${smtp.from}" subject="error" />

here is the question,how can I use Environment variables setted on cloudhub in java class.How can I get the smtp.host value in java class???

David told me that I can use them as they available as system properties. But How to use the system properties in java class..

Any advise?? Thanks a lot!

Andremoniy
  • 34,031
  • 20
  • 135
  • 241
user3787636
  • 31
  • 1
  • 7

2 Answers2

1

The best option is to inject them into your class via Spring. E.g.:

<bean class="my.java.Object">
  <property name="smtp" value="${smtp.host}">
</bean>

However, getting it as a system property via System.getProperty("smtp.host") will also work.

0

From a java class, just use System.getProperty("smtp.host");

Ryan Carter
  • 11,441
  • 2
  • 20
  • 27