SpringBoot+Swing打包报错:exception is java.awt.HeadlessException


    SpringBoot和Swing一起开发时,在eclipse中运行正常,没有报错, 但是在打包的时候就报错了

Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.xxx.gui.MainFrame]: Constructor threw exception; nested exception is java.awt.HeadlessException

(如果在eclipse中运行报错,则在启动类中加上System.setProperty("java.awt.headless", "false");) 


最后发现是打包时,执行了maven test,打包跳过测试就好了,打包就不会报错

方法1:

mvn install -DskipTests

mvn install -Dmaven.test.skip=true


方法2:

pom.xml中加上

<build>

<plugins>

<plugin>

<groupId>org.apache.maven.plugins</groupId>

<artifactId>maven-surefire-plugin</artifactId>

<version>2.21.0</version>

<configuration>

<skipTests>true</skipTests>

</configuration>

</plugin>

</plugins>

</build>




HeadlessException

2020.12.14 01:07

https://www.meihaocloud.com.com/1038.html , 欢迎转载,请在文章页标出原文连接 !


Copyright © 2020 千夕网 联系站长

粤公网安备 44030302001408号 粤ICP备19099833号-1