打成jar包后会报此错误: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'loginController' defined in URL;
第一步:先进行项目注解检查,检查是否有忘记@Controller,@Service,@Mapper的情况,并检查启动类有没有进行MapperScan()注解扫描,以排除是否为代码问题。
第二步:检查是否有导入外部jar包的情况,例如集成其他公司的短信模块时需要引入的外部jar,我就是这种情况,刚开始看到找不到bean,不要被误导.
问题的关键点在后面的Caused by:
Caused by: java.lang.NoClassDefFoundError: com.zjbd.bdsmssdk.base.Request
Caused by: java.lang.ClassNotFoundException: com.zjbd.bdsmssdk.base.Request
问题指向了引入外部jar,打成jar包后找不到相应的类,这里我参考并进行了搬运此博主的内容,与需要可以访问原地址进行参考: SpringBoot引入外部jar,并将项目打包成jar包,引发项目运行失败的问题_唐中的博客-CSDN博客
以下为搬运:
正常打包操作
- 在src/main/resource 目录下创建一个lib文件夹,将需要打如到项目中的jar放在这里
- 通过build path 将这些jar加入到工程中,以方便调用
- 在pom.xml中增加,其中xxx看实际情况而定
<dependencies>
<dependency>
<groupId>XXX</groupId>
<artifactId>XXX</artifactId>
<version>XXX</version>
<scope>system</scope>
<systemPath>${project.basedir}/src/main/resources/lib/XXX.jar</systemPath>
</dependency>
</dependencies>
————————————————
原文链接:https://blog.csdn.net/weixin_39472101/article/details/108338480
- 在pom.xml中增加build 逻辑
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<includeSystemScope>true</includeSystemScope>
</configuration>
</plugin>
</plugins>
<resources>
<resource>
<directory>lib</directory>
<targetPath>BOOT-INF/lib/</targetPath>
<includes>
<include>**/*.jar</include>
</includes>
</resource>
<resource>
<directory>src/main/resources</directory>
<targetPath>BOOT-INF/classes/</targetPath>
</resource>
</resources>
</build>
————————————————
原文链接:https://blog.csdn.net/weixin_39472101/article/details/108338480
特别注意: 上面的build中的代码仅仅是在打包的时候打开,在运行项目的时候,需要将上面的代码注释掉。不然会报错:找不到XXXMapper.xml mybatis对应的xml文件。