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>