Spring boot application provide option to set properties from command line like –server.port to change server port but in production server we requires to disable command like option while running spring boot application. Here is code for Spring boot disable command line properties options:

springApplication.setAddCommandLineProperties(false); // it will disable command like option, when set false then it will ignore command line option. then java -jar spring-boot-example-1.0-SNAPSHOT.jar --server.port=2020 will not work. because it will ignore option from command line. it good for production server if requirement match.

package com.javadeveloperzone;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
/**
 * Created by JavaDeveloperZone on 19-07-2017.
 */
@SpringBootApplication
@ComponentScan
// Using a root package also allows the @ComponentScan annotation to be used without needing to specify a basePackage attribute
public class SpringBootConfig {
    public static void main(String[] args) throws Exception {
        SpringApplication springApplication = new SpringApplication(SpringBootConfig.class);
        springApplication.setAddCommandLineProperties(false);  // it will disable command like option, when set false then it will ignore command line option.
        springApplication.run(args);
    }
}

References :

Spring Boot properties document

Was this post helpful?

Leave a Reply

Your email address will not be published. Required fields are marked *