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 ...
随机推荐
- pyhton:操作redis
一.redis介绍 redis是一种非关系型数据库:没有表结构,没有字段,没有sql语句.只是用get获取数据,set插数据,类似字典.比如mangodb,redis redis的数据全存在内存,re ...
- JWT理论理解
什么是JWT Json web token (JWT), 是为了在网络应用环境间传递声明而执行的一种基于JSON的开放标准(RFC 7519).该token被设计为紧凑且安全的,特别适用于分布式站点的 ...
- AtomicInteger原理&源码分析
转自https://www.cnblogs.com/rever/p/8215743.html 深入解析Java AtomicInteger原子类型 在进行并发编程的时候我们需要确保程序在被多个线程并发 ...
- @Autowried入门和源码分析
话不多说直接上代码: 声明一个接口userDao: package ioc.hello; public interface UserDao { public void test(); } 2个实现类: ...
- xss利用——BeEF#stage2(初始并持续化控制)
全文概览 浏览器攻击方法流程 攻击浏览器一般分为几个阶段,如下图 整个过程分为三个步骤,第一步是初始化控制,第二步是持续控制,第三步是攻击.在第三步中的七个攻击方法是可以交叉的,比如可以同时攻击用户和 ...
- MGRE及实验
tunnel 隧道:一种的简单的VPN技术: 普通的tunnel为点到点网络类型: 生成隧道接口,流量通过路由查询后,若通过隧道接口转发时,需要在原有的三层报头前,再添加一个公有地址间的报头: 将两个 ...
- 【Processing-日常1】小圆碰撞
之前在CSDN上发表过: https://blog.csdn.net/fddxsyf123/article/details/79741637
- IDEA搭建多模块maven项目
目录 新建maven项目作为多模块的parent项目 新建模块 在parent项目中配置 pom api 模块搭建restful风格api Mybatis Generator的使用(mybatis 逆 ...
- Spring Cloud实战 | 最终篇:Spring Cloud Gateway+Spring Security OAuth2集成统一认证授权平台下实现注销使JWT失效方案
一. 前言 在上一篇文章介绍 youlai-mall 项目中,通过整合Spring Cloud Gateway.Spring Security OAuth2.JWT等技术实现了微服务下统一认证授权平台 ...
- Java反应式框架Reactor中的Mono和Flux
1. 前言 最近写关于响应式编程的东西有点多,很多同学反映对Flux和Mono这两个Reactor中的概念有点懵逼.但是目前Java响应式编程中我们对这两个对象的接触又最多,诸如Spring WebF ...