On the custom parameter network red frame SpringBoot2.x of (a)

We all know that one of the most attractive places that he SpringBoot framework for the integration of the various components of the framework provides a default configuration, "zero-configuration" integration and development is its ultimate goal. In theory you do not do any special configuration, you can start the project.

If you use SpringBoot for web development projects, then he has built a web container, you do not need to deploy a separate container such as tomcat or jetty, packaged into a jar package to run, eliminating the need for packaging deployment process locked in. By default, initiated by SpringBoot web project, the default port is 8080, which is the default port jetty or tomcat's. So the question is, how do I want to change the port, which is bound to encounter problems.

Remember when running SpringBoot project, main methods need to write it, when the code is as follows:

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

Note that this is a main method, dynamic startup parameters passed, this one with ordinary run java program makes no difference. args is his startup parameters, it is an array, you can take one or more parameters.
Then this parameter is used to do what? Since springboot do most of the default configuration, then you want to modify these configurations, the main method is performed by passing parameters will automatically do the cover frame configuration for you.

For example, you can use code similar to the following, you start to modify the port project:

java -jar xxx.jar --server.port=8888

As another example, you may like the following code to modify your logo project started in console output,

java -jar xxx.jar --spring.banner.location=classpath:banner.txt

The net effect is to start, you often see this
On the custom parameter network red frame SpringBoot2.x of (a)
replaced with this:
On the custom parameter network red frame SpringBoot2.x of (a)
like, you can also customize many other default settings, of course, some need to add the appropriate module relies in pom file, you can use the corresponding function. For example, you used the redis, then you need to add a
spring-boot-starter-data- redis redis to the default settings of the loaded first come, on this basis, you can write custom parameters, such as:

java -jar xxx.jar --spring.redis.port=6379

Note that the format of the command is:

#参数需要跟在jar包名称之后以--开头
java -jar xxx.jar --参数名=参数值   

You can also run while adding more custom parameters (separated by spaces), such as the above-mentioned several examples of merged it is:

java -jar xxx.jar --server.port=8888 --spring.banner.location=classpath:banner.txt --spring.redis.port=6379

In theory, can support custom parameters can be added.

Incidentally, to help you with this IDE IDEA or Myeclipse run project, the principle is true.

Well, now there are two problems emerged.

1, how do I know which custom parameters springboot support?

2, so many parameters are written to run on command it? Would not that be will look very bloated, looks like that is not elegant?

These two issues, leaving to the next talk.

Guess you like

Origin blog.51cto.com/1241490/2475537