简体   繁体   中英

Loading credentials from config

I am writing simple rest client with spring boot. In my service class i am using RestTemplate. How to avoid hardcoding url and ApiKey? I tried to use application.properties file and Value annotation but i get null pointer exception. Edit: Injected fields via constructor (using Value annotation). Is it a good practice?

It is wise of you to not want to store url and ap ikey in your application.

I recommend having a properties file stored in your home directory and then reference that file at startup time.

java -jar app.jar --spring.config.location=classpath:/another-location.properties *

*Taken from Properties with Spring and Spring Boot .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM