java - Unable to read application.properties in spring boot application -


i unable read application.properties value in project in classes injected bean project. project using project has classes needs read configuration application.properties. mine maven project , spring boot application having application.properties in src/main/resources folder , properties values defined in it. missing unable read file values? or there other mechanism setting these properties classes loaded via component-scan

below line of code works fine, able read value application.properties: @postconstruct void init() throws classnotfoundexception, ioexception { system.out.println(context.getenvironment().getproperty("env.host", "default value")); }

now there project using in mine. when loading classes beans getting initialized dependency of class, there tries read same value in constants file as

   static final string host_property = "${env.host}"; 

there value not getting initialized value applictaion.properties

if want application.properties values,you have 2 option. 1) can autowire environment class , use getproperty() method as

@autowired environment env; env.getproperty("${env.host}"); 

2)@value annotation

@value("${env.host}")     string host_property; 

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -