简体   繁体   中英

Spring Boot: configuration does not load correctly my password variable from application.yml

I'm facing a problem using Spring Boot configurations:

My configuration is not loaded correctly for all of my parameters.

I'm using a profile (in my case 'qualif') with application-qualif.yml configuration file but values from it are not overwriting application.yml values. This behaviour is expected.

Also i'm using Lombok.

My application.yml here:

mail:
  login:    'login'
  address:  'login@email.com'
  password: 'myRealPassword'

My application-qualif.yml here:

spring:
  otherValues: ...

My configuration here:

@Configuration
@Getter
public class SmtpConfiguration {
    @Value("${mail.login}")
    private String login;

    @Value("${mail.address}")
    private String address;

    @Value("${mail.password}")
    private String password;
}

When I try to display password it always return me '123456' but I can't find any reference of '123456' in my project. It's expected to be myRealPassword here.

log.printf(Level.INFO, "Mail password: " + smtpConfiguration.getPassword());

Other values from smtpConfiguration return same value from application.yml

2021-08-19 10:55:26.102 INFO  192494 --- [   scheduling-1] x.x.x.x.x.x.XXXScheduledTask: 
Attempt to send mail using login@email.com with password 123456

Console output:

2021-08-19 10:48:49.572 INFO  192412 --- [   scheduling-1] x.x.x.x.x.x.XXXService: 
Mail password: 123456

This code is run under Linux env and it's working on my local computer (Windows) using no profiles.

Thanks for reply.

I found the issue.

It seems that linux env variable named MAIL_PASSWORD exists and equals to '123456'.

I didn't know this was overwriting YAML values if the configuration does not specified it like:

mail:
  password: ${mail.password}

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