java.awt.headless,Springboot java.awt.HeadlessException

编者

希望在Springboot当中显示显示GUI,但是发现在SpringApplication之前可以时候,之后无法使用。

初次碰到

希望在Springboot启动之后开启窗口

@SpringBootApplication

public class xxxServerApplication {

private static final Logger logger = LoggerFactory.getLogger(xxxServerApplication.class);

public static void main(String[] args) throws FrameGrabber.Exception, InterruptedException {

logger.info("Server Main Start");

SpringApplication.run(xxxServerApplication.class, args);

CanvasFrame canvas = new CanvasFrame("Title");//新建一个窗口

}

错误报告

Exception in thread "main" java.awt.HeadlessException

at java.awt.GraphicsEnvironment.checkHeadless(GraphicsEnvironment.java:204)

at java.awt.Window.(Window.java:536)

at java.awt.Frame.(Frame.java:420)

at javax.swing.JFrame.(JFrame.java:233)

at org.bytedeco.javacv.CanvasFrame.(CanvasFrame.java:124)

at org.bytedeco.javacv.CanvasFrame.(CanvasFrame.java:121)

at org.aicfve.rtmp.server.xxxServerApplication.main(xxxServerApplication.java:27)

搜索

Disable Headless Mode

Spring Boot 应用默认情况下运行在headless模式。意味着运行在没有GUI的服务器或者其他环境。

.headless(false)

不这么做,任何AWT GUI元素都将会抛出java.awt.HeadlessException异常

你可能感兴趣的:(java.awt.headless,Springboot java.awt.HeadlessException)