Reputation: 31
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!
Upvotes: 0
Views: 1719
Reputation: 19
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.
Upvotes: 1