0

I have an application where I would like to change a datasource password that is stored in a application.yml file. The password in the YML file is stored such as this:

----
spring:
    profiles: production
datasource:
    password: prodpassword

Note: I also have profiles for development and stage.

The password prop is set on a class using ConfigurationProperties such as follows:

@Component
@ConfigurationProperties(prefix="datasource")
public class DataSourceConnector {

    private password;

    public void setPassword(String password) {
        this.password = password;
    }

Now, I try to override the prodpassword with prodpa$$word via a command line arg but it doesn't work:

java -Dspring.profiles.active=production -jar /usr/share/myapp/myapp-1.0.jar --datasource.password='prodpa$$word'

I also tried creating an identical (except the new password) application.yml file outside of the jar. That doesn't work either.

java -Dspring.profiles.active=production -jar /usr/share/myapp/myapp-1.0.jar --spring.config.location=/usr/share/myapp/

Note: I left out the file name in the location param due to this note from http://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#boot-features-external-config-profile-specific-properties:

If you have specified any files in spring.config.location, profile-specific variants of those files will not be considered. Use directories inspring.config.location if you also want to also use profile-specific properties.

How can I override datasource.password within the application.yml of the jar?

Edit: The application is being started / stopped using supervisorctl.

James
  • 2,876
  • 18
  • 72
  • 116
  • Have you tried `-Dspring.config.location=/usr/share/myapp/`? – jny Apr 25 '16 at 20:43
  • You can view my answer to a similar question here: http://stackoverflow.com/questions/36635163/spring-boot-externalizing-properties-not-working/36635367#36635367 – Marco Tedone Apr 25 '16 at 21:22
  • Thanks. I tried that, but it did not work. It turns out that issue was unrelated to Spring. It was due to the way that I was running the application. The application runner (supervisorctl) was caching my config file (between application starts and stops). Sorry I did not include that in my OP. – James Apr 25 '16 at 21:24

1 Answers1

0

After changing the config file that contains the java command, supervisorctl must reread the change:

supervisorctl reread

Next, activate the changes with:

supervisorctl update
James
  • 2,876
  • 18
  • 72
  • 116