首页 技术 正文
技术 2022年11月15日
0 收藏 398 点赞 2,431 浏览 2310 个字

Code-Review-SpringBoot-Maven编译(第三方jar包引用)

  在使用maven编译项目时,有时候咱们可能会使用一些第三方的jar包依赖库,比如第三方支付类的接入,大多出于安全考虑,会单独给提供jar包,可是这些jar包依赖库又没有在共有的maven仓库。 一般只能下来放到本项目的lib目录下。如果在打包的时候不进行拷贝处理,会导致打包后的target.jar中不会有lib文件夹中的相关第三方jar包。 打包后没法运行起来,所以需要对第三方jar进行单独处理,让maven打包时可以把使用到外部jar打进去。主要就是在build中加resourcesapache。

  备注:pom.xml的配置很重要。

观察完整的pom.xml配置文件,重点关注resources 节点包含了俩个  resource 。一个指定的第三方jar包的位置。一个指定了配置文件的位置。resource的配置至关重要。如果你没有配置

<resource>
<directory>src/main/resources</directory>
<targetPath>BOOT-INF/classes/</targetPath>
</resource>

的情况下:你很大概率会遇到:

2020-12-28 16:28:08.947  WARN 18018 — [           main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization – cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘projectingArgumentResolverBeanPostProcessor’ defined in class path resource [org/springframework/data/web/config/ProjectingArgumentResolverRegistrar.class]: BeanPostProcessor before instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration’: BeanPostProcessor before instantiation of bean failed; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ‘org.springframework.cache.annotation.ProxyCachingConfiguration’

bean装载的异常,主要原因就是没有找到相关的配置文件导致的。

编译后的依赖文件(maven依赖以及第三方jar)位置:/BOOT-INF/lib 。

自己项目编译后文件(其中应该包含配置文件):BOOT-INF/classes



重点: 完整的pom.xml配置,以下是完整pom.xml build配置节。

<build>
<defaultGoal>compile</defaultGoal>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin> <plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
<compilerArguments>
<!-- 打包本地jar包 -->
<extdirs>${project.basedir}/src/libs</extdirs>
</compilerArguments>
</configuration>
</plugin>
</plugins> <resources>
<resource>
<directory>${project.basedir}/src/libs</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>

以上是解决 用maven编译项目时,集成第三方jar包的解决方案。我在自己的项目中实际测试后,部署成功。如果疑问,请留言沟通。祝好。

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,121
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,593
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,438
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,209
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,845
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,930