Solution of invalid parameters when springboot project starts

  • 2021-11-13 01:25:51
  • OfStack

Invalid Parameters When Catalog springboot Project Startup Change run Method Parameters Add args Parameters as follows springboot Project Startup Parameter Setting Problems Spring boot Project Commonly Used Startup Methods war Package Deployment Methods

Invalid parameters when springboot project starts

Today, I started an springboot project and found that all the parameters I entered when I started could not take effect, but the configuration of yaml file took effect. After checking for half a day, I finally found that there was a problem in the original startup class. The original code is as follows


public class Application {
    public static void main(String[] args) {
        SpringApplication.run(Application.class);
    }
}

Change the parameters of run method and add args parameters as follows


public class Application {
    public static void main(String[] args) {
        SpringApplication.run(Application.class,args);
    }
}

After startup, the specified parameters take effect.

springboot Project Startup Parameter Setting Problem

Several Commonly Used Startup Modes of Spring boot Project

Maven startup specifies that Profile passes through-P, such as mvn spring-boot: run-P test, but this is Profile of Maven.

If you want to specify spring. profiles. active for spring-boot, you must use mvn spring-boot: run-Drun. profiles=test If you run the jar file directly from the command line, use java-jar-Dspring. profiles. active = test demo-0. 0.1-SNAPSHOT. jar If you use the development tool and run the Application. java file to start, add the parameter spring. profiles. active=test

war package deployment mode

For war package deployment mode, you need to make the following configuration in the startup class


public class TestApplication extends SpringBootServletInitializer {
    public static void main(String[] args) {
        SpringApplication.run(TestApplication.class, args);
    }
    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(TestApplication.class);
    }
}

Related articles: