maven build時出現如下錯誤提示日誌:java
[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:1.3.5.RELEASE:repackage (default) on project information: Execution default of goal org.springframework.boot:spring-boot-maven-plugin:1.3.5.RELEASE:repackage failed: Unable to find a single main class from the following candidates [com.hhly.InformationApplication, com.hhly.test.Application] -> [Help 1]
Unable to find a single main class from the following candidates [com.hhly.InformationApplication, com.hhly.test.Application] // 不能從下面的候選類中找到單一的main類
查看着兩個類,發現兩個類中確實兩個類中均有一個main方法,去掉一個多餘的main方法,保留惟一的main方法。spring
生產對應的jar包以後,經過一下命令運行spring boot程序,sql
java -jar information-0.0.1-SNAPSHOT.jar
查找資料發現爲最後生成的jar包中的META-INF/MANIFEST.MF文件,沒有設置主函數信息。猜測是pom.xml設置的問題,比對網上的設置,發現多數配置都是以下:apache
<build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>1.8</source> <target>1.8</target> </configuration> </plugin> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <configuration> <maimClass>com.hhly.InformationApplication</maimClass> </configuration> <executions> <execution> <goals> <goal>repackage</goal> </goals> </execution> </executions> </plugin> </plugins> </build>
比對本身的設置發現:本身在標籤外面還包了一個 pluginManagement標籤。app
去掉pluginManagement標籤。maven
首先經過maven clean,而後再執行maven build,在執行main函數時會出現下面錯誤,詳細日誌以下:函數
2016-09-09 18:29:43.419 WARN 37076 --- [ost-startStop-1] o.s.b.f.s.DefaultListableBeanFactory : Bean creation exception on non-lazy FactoryBean type check: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userMapper' defined in file [D:\neon-workspace\information \target\classes\com\hhly\dao\UserMapper.class]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Property 'sqlSessionFactory' or 'sqlSessionTemplate' are required
一樣的代碼,在經過Alt + F5更新項目,而後maven build生成jar包,最後執行的main的時候也就不會報錯。spring-boot
調整打包順序以下:
一、Alt + F5
二、maven buildui