简体   繁体   中英

Should I use headless mode in Spring-boot based backend?

I'm working on a application based on a simple monolithic architecture:rest API backend with spring-boot + frontend with a Js framework.

I have been reading about the headless mode when running java apps and I would like to know if running the embedded tomcat with my spring-boot application in headless mode is a good idea.

In general, running an application in a console requires some sort of terminal to write to.

In Unix-based systems, these terminals are referred to as tty .

This implies the following:

Whenever you open a connection to your server via SSH, you get a tty. Your non-headless application will run in that tty until the tty is closed. To avoid that, you'd need something like screen .

For Windows systems: If you close the cmd window of the console/sign off the user, the application server will also stop running.

That's why productive installations are usually headless and service based.

So much for the background, the official docs actually state the following:

In addition to running Spring Boot applications by using java -jar, it is also possible to make fully executable applications for Unix systems. A fully executable jar can be executed like any other executable binary or it can be registered with init.d or systemd. This helps when installing and managing Spring Boot applications in common production environments.

This is described here .

Generally you don't need to specify -Djava.awt.headless=true because since around Java 1.8 the JRE determines itself whether a graphics environment is available or not and switches into headless mode if no graphics environment is available.

Relevant source in Java 11: https://github.com/openjdk/jdk11/blob/master/src/java.desktop/share/classes/java/awt/GraphicsEnvironment.java#L166

  • if you are running a Unix-like operating system and the DISPLAY environment variable is not set the headless is true
  • on Windows it is assumed that a graphics device is always present and therefore headless is false

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM