Spring boot 打成jar包问题总结

Spring boot 打成jar包问题总结

1、Unable to find a single main class from the following candidates

1.1、问题描述

maven build时出现以下错误提示日志:

[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]

1.2、日志分析

Unable to find a single main class from the following candidates [com.hhly.InformationApplication, com.hhly.test.Application]
// 不能从下面的候选类中找到单一的main类

1.3、解决办法

查看着两个类,发现两个类中确实两个类中均有一个main方法,去掉一个多余的main方法,保留唯一的main方法。

2、jar中没有主清单属性

2.1、问题描述

生产对应的jar包之后,通过一下命令运行spring boot程序,

java -jar information-0.0.1-SNAPSHOT.jar

jar中没有主清单属性

2.2、问题分析

查找资料发现为最后生成的jar包中的META-INF/MANIFEST.MF文件,没有设置主函数信息。猜想是pom.xml设置的问题,比对网上的设置,发现多数配置都是如下:

   <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标签。

2.3、解决办法

去掉pluginManagement标签。

3、Property ‘sqlSessionFactory’ or ‘sqlSessionTemplate’ are required

3.1、问题描述

首先通过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

3.2、问题分析

同样的代码,在通过Alt + F5更新项目,然后maven build生成jar包,最后执行的main的时候也就不会报错。

3.3、解决办法

调整打包顺序如下: 
1、Alt + F5 
2、maven build

猜你喜欢

转载自my.oschina.net/u/2351298/blog/1612266