spring boot:在项目中引入第三方外部jar包集成为本地jar包(spring boot 2.3.2)
一,为什么要集成外部jar包?
不是所有的第三方库都会上传到mvnrepository,
这时我们如果想集成它的第三方库,则需要直接在项目中集成它们的jar包,
在操作上还是很简单的,
这里用luosimao的短信平台sdk演示一下
说明:刘宏缔的架构森林是一个专注架构的博客,地址:https://www.cnblogs.com/architectforest
对应的源码可以访问这里获取: https://github.com/liuhongdi/
说明:作者:刘宏缔 邮箱: 371125307@qq.com
二,下载并添加到项目
项目结构如图:

三,项目中配置pom.xml
配置pom.xml
<!--luosimao send sms begin-->
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>api</artifactId>
<version>1.19</version>
<scope>system</scope>
<systemPath>${project.basedir}/src/main/resources/jar/jersey-bundle-1.19.jar</systemPath>
</dependency> <dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/src/main/resources/jar/json-org.jar</systemPath>
</dependency>
<!--luosimao send sms end-->
<configuration>
<includeSystemScope>true</includeSystemScope>
</configuration>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<includeSystemScope>true</includeSystemScope>
</configuration>
</plugin>
</plugins>
</build>
四,用官方的例子添加一段java代码,并测试效果
1,HomeController.java
@RestController
@RequestMapping("/home")
public class HomeController { //查询剩余短信条数状态
@GetMapping("/status")
public String status() {
//Api api = new Api();
String httpResponse = testStatus();
try {
JSONObject jsonObj = new JSONObject( httpResponse );
int error_code = jsonObj.getInt("error");
if( error_code == 0 ){
int deposit = jsonObj.getInt("deposit");
System.out.println("Fetch deposit success :"+deposit);
}else{
String error_msg = jsonObj.getString("msg");
System.out.println("Fetch deposit failed,code is "+error_code+",msg is "+error_msg);
}
} catch (JSONException ex) {
//Logger.getLogger(Api.class.getName()).log(Level.SEVERE, null, ex);
ex.printStackTrace();
} return httpResponse;
} //发送并返回对状态的查询
private String testStatus(){
Client client = Client.create();
client.addFilter(new HTTPBasicAuthFilter(
"api","key-thisisakeydomoforlaoliutest"));
WebResource webResource = client.resource( "http://sms-api.luosimao.com/v1/status.json" );
MultivaluedMapImpl formData = new MultivaluedMapImpl();
ClientResponse response = webResource.get( ClientResponse.class );
String textEntity = response.getEntity(String.class);
int status = response.getStatus();
return textEntity;
}
}
官方的demo代码,我们集成到controller中测试效果
2,测试效果
访问:
http://127.0.0.1:8080/home/status
返回:
{"error":0,"deposit":"88888888"}
返回了剩余的短信条数,说明我们对外部jar包的集成是有效的
六,查看spring boot版本
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.3.2.RELEASE)
spring boot:在项目中引入第三方外部jar包集成为本地jar包(spring boot 2.3.2)的更多相关文章
- vue-cli项目中引入第三方插件
前言 最近有小伙伴问道如何在vue-cli项目中引入第三方插件或者库,例如如果想在项目中使用jQuery中的Ajax请求数据呢?或者我想使用Bootstrap框架呢?等等这些问题,本篇博客将带你学习如 ...
- vue-cli创建的项目中引入第三方库报错 'caller', 'calle', and 'arguments' properties may not be...
http://blog.csdn.net/sophie_u/article/details/76223978 以在vue中引入mui第三方库为例: 虽然针对vue,有单独的vue-mui库可以使用,但 ...
- vue-cli创建的项目中引入第三方库报错'caller', 'calle', and 'arguments' properties may not be...
本文链接:https://blog.csdn.net/Sophie_U/article/details/76223978 问题: 在vue的main.js中引入mui.min.js时,报错. 如上,单 ...
- vue项目中引入第三方框架
element-ui npm install element-ui -- save; main.js中 import Element from 'element-ui'; import 'elemen ...
- 在Android项目中引入MuPdf
由于公司手机App要加入一个附件查看功能,需要查看PDF文件,在网上找了许多第三方工具,最后选择了MuPDF. 更多第三方工具可以查看大神总结的:http://www.cnblogs.com/poke ...
- Java SE Eclipse中引入第三方jar及class
使用eclipse开发Java SE 总免不了需要引入第三方的jar或者calss文件.这里给大家说一下如何在eclipse中引入第三方jar或者calss文件. 让我们先了解一下eclipse项目中 ...
- 项目中整合第三方插件与SpringMVC数据格式化关于ip地址
一.Bootstrap 响应式按钮 <div calss="col-sm-2"> <button class="btn btn-default btn- ...
- 创建swagger的springboot-stater,并在spring cloud zuul网关中引入
Swagger 是一款RESTFUL接口的.基于YAML.JSON语言的文档在线自动生成.代码自动生成的工具. 通过在controller中添加注解,即可轻易实现代码文档化. Swagger提供ui界 ...
- Laravel Controller中引入第三方类库
Laravel 引入第三方类库 在Controller中引入自定义的php文件,先在app目录下创建一个新的文件夹,命名Tools(可自定义),接着创建一个MyTest.php: <?php c ...
随机推荐
- Scrapy框架的架构原理解析
爬虫框架--Scrapy 如果你对爬虫的基础知识有了一定了解的话,那么是时候该了解一下爬虫框架了.那么为什么要使用爬虫框架? 学习框架的根本是学习一种编程思想,而不应该仅仅局限于是如何使用它.从了解到 ...
- ios网络访问官方演示程序
官方演示程序 AppDelegate 设置缓存 NSURLCache *URLCache = [[NSURLCache alloc] initWithMemoryCapacity:4 * 1024 * ...
- 初等函数——幂函数(Power Function)
幂函数(Power function)是形如f(x)=xa的函数,a∈R是实数.即以底数为自变量,幂为因变量,指数为常数的函数称为幂函数. 性质 幂函数的图像一定会出现在第一象限内,一定不会出现在第四 ...
- Linux实战(11):Centos后期添加网卡配置
前言 最近在折腾网卡,发现在已装centos上的机器上直接加网卡,开机后在系统中是没有启动的,下面的步骤是启动的过程,大家可以参考一下. 正文 首先我们先看网卡配置目录下的文件跟网卡 查询UUID y ...
- mysql读写分离--一主多从,冗余存储
转载了https://blog.csdn.net/u013421629/article/details/78793966 https://blog.csdn.net/justdb/article/de ...
- spring boot之AOP
首先,aop是面向对象切面,嗯,就是说不面向静态方法,我做测试demo的时候controller方法有个加了static,尴尬的是就用了那个方法测,检查了几遍配置... 参看这篇文章https://m ...
- Springboot+Vue实现仿百度搜索自动提示框匹配查询功能
案例功能效果图 前端初始页面 输入搜索信息页面 点击查询结果页面 环境介绍 前端:vue 后端:springboot jdk:1.8及以上 数据库:mysql 核心代码介绍 TypeCtrler .j ...
- 计算几何(一):凸包问题(Convex Hull)
引言 首先介绍下什么是凸包?如下图: 在一个二维坐标系中,有若干点杂乱排列着,将最外层的点连接起来构成的凸多边型,它能包含给定的所有的点,这个多边形就是凸包. 实际上可以理解为用一个橡皮筋包含住所有给 ...
- centos 启动 elasticsearch 失败集
环境: elasticsearch 6.5.2, java 连接失败 启动后当你 使用 curl http://localhost:9200 测试时,得到如下结果 Curl: (7) Failed c ...
- 山寨一个Spring的@Component注解
1. 前言 我们在上一篇对Mybatis如何将Mapper接口注入Spring IoC进行了分析,有同学问胖哥这个有什么用,这个作用其实挺大的,比如让你实现一个类似@Controller的注解(或者继 ...