java - Spring Boot - Configuration Value from yml is null -


im loading configuration yml using spring configuration annotations. working fine 3 of 4 values configured. 4th value null.

since other values loading dont think there configuration error. im clueless...

here code:

yml-file

spring:     profiles: test  airtable:     api-key: xxx     base: xxx     proxy: "localhost:8095"     url: testurl  mail:     subjectprefix: r750explorer develop -  

propertiesclass

@configuration @configurationproperties(prefix = "airtable") public class airtableproperties {  @notnull private string apikey;  @notnull private string base;  private string proxy;  private string url;   public string getapikey() {     return apikey; }  public void setapikey(string apikey) {     this.apikey = apikey; }  public string getbase() {     return base; }  public void setbase(string base) {     this.base = base; }  public string getproxy() {     return proxy; }  public void setproxy(string proxy) {     this.proxy = proxy; }  public string geturl() {     return url; }  public void seturl(string url) {     this.url = url; }   } 

autowired them here

public class airtablerepository {  private final org.slf4j.logger log =  loggerfactory.getlogger(this.getclass());  private base base = null;  @autowired private airtableproperties prop; 

main application file

@springbootapplication @enablecaching @enablescheduling @enableconfigurationproperties public class application extends springbootservletinitializer {   public static void main(string[] args) throws exception { . . .  public static void main(string[] args) throws exception {      springapplication.run(application.class, args); } } 

so values define in api-key,base , proxy. url null.

========================= edit =============================

update. use both default application.yml , profile specific application-test.yml

the above yml application-test yml. heres application.yml

spring:     application:         name: r750explorer      boot:         admin:             #url: http://localhost:8085             devtools:         restart:             additional-paths: src, target             exclude: "**/*.log"      mail:         properties:             mail:                 smp:                    connectiontimeout: 5000                    timeout: 3000                    writetimeout: 5000      mvc:         view:             prefix: /web-inf/jsp/             suffix: .jsp      output:         ansi:             enabled:      profiles:         #default: default         #active: dev       airtable:         api-key: none-default       mail:         from-address: xxx         to-address: xxx         user: xxx         password: xxx  server:     address: 127.0.0.1     #port: 9000     compression:         enabled: true     session:         cookie:             #comment: # comment session cookie.             # domain: # domain session cookie.             http-only: true             # -> ein jahr / maximum age of session cookie in seconds.             max-age: 31536000             #name:  session cookie name.             #path: # path of session cookie.             # "secure" flag session cookie.             secure: true      logging:     file: logs/r750explorer.log     level:         com:             sybit: debug  management:     context-path: /manage     security:          enabled: false         # roles: superuser  security:     user:         #name: admin         #password=**** 

now heres clue: if add url: testurl in default application.yml under airtable writes value. doesent in application-test.yml. although case url not proxy etc, working fine.

it works me without changes :

application.yml :

airtable:     api-key: xxx     base: xxx     proxy: localhost:8095     url: testurl 

pojo :

@configuration @configurationproperties(prefix = "airtable") public class airtableproperties {      @notnull     private string apikey;      @notnull     private string base;      private string proxy;      private string url;      public string getapikey() {         return apikey;     }      public void setapikey(string apikey) {         this.apikey = apikey;     }      public string getbase() {         return base;     }      public void setbase(string base) {         this.base = base;     }      public string getproxy() {         return proxy;     }      public void setproxy(string proxy) {         this.proxy = proxy;     }      public string geturl() {         return url;     }      public void seturl(string url) {         this.url = url;     }      @override     public string tostring() {         return "airtableproperties{" +                 "apikey='" + apikey + '\'' +                 ", base='" + base + '\'' +                 ", proxy='" + proxy + '\'' +                 ", url='" + url + '\'' +                 '}';     } 

output :

   props airtableproperties{apikey='xxx', base='xxx', proxy='localhost:8095', url='testurl'} 

Comments