使用springboot+maven出现的问题

来源:互联网 发布:Cisco网络排错 编辑:程序博客网 时间:2024/06/05 20:47

问题描述:
springboot 在执行maven install 时候出现以下错误

[INFO] ------------------------------------------------------------------------[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:1.4.2.RELEASE:repackage (default) on project springcloud-common: Execution default of goal org.springframework.boot:spring-boot-maven-plugin:1.4.2.RELEASE:repackage failed: Unable to find a single main class from the following candidates [com.itmuch.cloud.common.Application, com.itmuch.cloud.common.utils.SmsUtils] -> [Help 1][ERROR] [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.[ERROR] Re-run Maven using the -X switch to enable full debug logging.[ERROR] [ERROR] For more information about the errors and possible solutions, please read the following articles:[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginExecutionException

解决办法:
1、在pom.xml文件中加入主类,用于指定加载的主类(在properties中,加入一个start-class的属性,用于告诉spring boot maven plugin哪个类是入口类即可)

<properties>        <start-class>com.itmuch.cloud.common.Application</start-class>    </properties>

2、在build中添加如下配置

<build>  ...  <plugins>    ...    <plugin>      <groupId>org.springframework.boot</groupId>      <artifactId>spring-boot-maven-plugin</artifactId>      <version>1.4.0.RELEASE</version>      <configuration>        <mainClass>${start-class}</mainClass>        <layout>ZIP</layout>      </configuration>      <executions>        <execution>          <goals>            <goal>repackage</goal>          </goals>        </execution>      </executions>    </plugin>    ...  </plugins>  ...</build>

最好执行maven install即可

[INFO] ------------------------------------------------------------------------[INFO] BUILD SUCCESS[INFO] ------------------------------------------------------------------------[INFO] Total time: 10.173 s[INFO] Finished at: 2017-07-01T23:46:02+08:00[INFO] Final Memory: 23M/277M[INFO] ------------------------------------------------------------------------