Spring overriding boot properties file from command line

I have a problem with Spring calling Boot and fat jar from command line. I am trying to override a property from the command line but with no success.
I have a parameter in the code:

@Value("${param1}")
private String param1;

      

and also i put application.properties file inside src \ main \ resources with the following content;

param1 = parameter value 1 from properties file

When I create a jar and run with:

java -jar java-apns-notifier-0.1.0.jar --param1 = Aaaaaaaaa

param1 is printed with the value from the application.properties file and ignores the value from the command line.
Project source code here

Any idea?

+3


source to share


1 answer


You forgot to pass arguments to your application class. You just need to change

SpringApplication.run(Application.class);

      



to

SpringApplication.run(Application.class, args);

      

+10


source







All Articles