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

  • 5
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 5
    评论
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值