Spring Boot runs in the background in jar package mode

Source: Internet
Author: User

Spring-boot jar Package Mode boot:
First, to prevent and common Tomcat 8080 port conflicts, set the port number of the Spring-boot project to 9090.
Specific method: Write server.port=9090 in the Application.properties file.
Use the MAVEN command: Clean package packaging.
Put it in a suitable location on the server.
Use the Java-jar Spring-boot01-1.0-snapshot.jar command to start the jar package.
The data returned in JSON format can then be seen in the browser input Http://124.232.163.150:9090/hello.

However, in this way, the service cannot be accessed as long as the console is closed. Below we make the jar package run in the background.

-jar spring-boot01-1.0-SNAPSHOT.jar > log.file 2>&1 &
    • 1
    • 1

For an explanation of the above command:

    1. Bash 0, 1, 23 numbers represent Stdin_fileno, Stdout_fileno, Stderr_fileno, that is, standard input (usually keyboard), standard output (usually the display, accurate is the user Terminal console), standard error (Error message output).
number
0 standard input (usually keyboard)
1 standard output (typically the display, exactly the user Terminal console)
2 standard error (Error message output)

2. Input and output can be redirected, so-called redirect input is to specify a specific input source in the command, such as Cat < test.c redirect test.c to the input source of the cat command. Output redirection is to specify a specific output target to replace the default standard output, such as   ls > 1.txt   Redirects the results of LS from standard output to 1.txt text.  
Sometimes you can see the same kind of notation as LS >> 1.txt.  
;   and   >>   The difference is: ;   for new and   >>   for appending. That is   ls > 1.txt   Creates a new 1.txt file and outputs the contents of LS to the new 1.txt, while   ls >> 1.txt   is already present in 1.txt, and we just want to append the LS content to the 1.txt text.  
3. The default input is only one (0,stdin_fileno), and the default output is two (standard output 1 Stdout_fileno, standard error 2 Stderr_fileno). So by default, the shell output error message is output to 2, and the normal output information is output to 1. But in some cases, we want to see all the information (including standard output information and error messages) under a terminal, what to do? Yes, you can use the output redirection we've described above. The idea has, how to write it? The very intuitive idea is   2>1   (redirect 2 to 1), OK? Try it and know it. We perform the following test steps:

step command
1 mkdir Test && CD test Create Test folder and enter test Table of Contents
2 touch a.txt B.C C create A.txt, B.C, c three files
3 ls > 1 According to our guess, this should be to redirect the results of LS to standard output, So the effect and direct LS should be the same. But after the actual execution of this sentence, there is no information in the standard output
4 ls after executing 3 again LS, You will see one more file in the Test folder 1
5 cat 1 View the contents of file 1, actual Result: 1 a.txt B.C c

ls > 1 ls instead of redirecting the results to standard output in step 3, the results are redirected to a file 1. That is, 1 is not interpreted here as Stdout_fileno, but as a file 1.
4. At this point, you should also be able to guess the purpose of 2>&1. Yes, 2>&1 is used to redirect standard error 2 to standard output 1. The & in front of 1 here is to let Bash interpret 1 as standard output instead of file 1. As for the last &, bash is executed in the background.

If this time, I want to turn off the Spring Boot service running in the background, I want to do this:

PS aux | grep Spring | Xargs kill-9

At this point, the console displays:

Resources:
Spring boot jar background run-Tea daddy's column-Blog channel-csdn.net
http://blog.csdn.net/xiaoyu411502/article/details/48520239

Spring Boot runs in the background in jar package mode

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.