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