I have a spring boot application and I would like to run it headless. When I run from the terminal this is the command I'm using:
java -jar myapp.jar --spring.main.headless=true
Is this correct? Any help is well appreciated.
Headless mode is a system configuration in which the display device, keyboard, or mouse is lacking. Sounds unexpected, but actually you can perform different operations in this mode, even with graphic data.
Headless mode This means that your Java application does not display windows or dialog boxes, does not accept keyboard or mouse input, and does not use any heavyweight AWT components. This mode is selected by specifying Java property java. awt. headless=true on the Java invocation.
HeadlessException is a runtime exception in Java that occurs when code that is dependent on a keyboard, display or mouse is called in an environment that does not support a keyboard, display or mouse.
I've faced with same problem and solved it using SpringApplicationBuilder
class. You should set headless
false (which is true by default). See javadoc.
My main method looks like this:
public static void main(String[] args) {
SpringApplicationBuilder builder = new SpringApplicationBuilder(App.class);
builder.headless(false).run(args);
}
The spring.main.*
properties are injected into the SpringApplication
. It doesn't know anything about heads or headlessness. Maybe you need java -Djava.awt.headless=true ...
?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With