学习ip2region
Springboot在使用ip2region的时候一直在报
java.io.FileNotFoundException: ip2region.xdb file path (系统找不到指定的文件。)
找了半天找到了这个(spring boot 整合 ip2region(ip地址库))
直接解决了
// 官网的例子
//searcher = Searcher.newWithFileOnly(dbPath);
// 解决方法
File file = ResourceUtils.getFile("classpath:" + "ip2region.xdb");
searcher = Searcher.newWithFileOnly(file.getAbsolutePath());
完整代码
public static void main(String[] args) {// 1、创建 searcher 对象String dbPath = "ip2region.xdb file path";Searcher searcher = null;try {//searcher = Searcher.newWithFileOnly(dbPath);File file = ResourceUtils.getFile("classpath:" + "ip2region.xdb");searcher = Searcher.newWithFileOnly(file.getAbsolutePath());} catch (Exception e) {System.out.printf("failed to create searcher with `%s`: %s\n", dbPath, e);return;}String ip = "127.0.0.1";// 2、查询try {long sTime = System.nanoTime();String region = searcher.search(ip);long cost = TimeUnit.NANOSECONDS.toMicros((long) (System.nanoTime() - sTime));System.out.printf("{region: %s, ioCount: %d, took: %d μs}\n", region, searcher.getIOCount(), cost);} catch (Exception e) {System.out.printf("failed to search(%s): %s\n", ip, e);}// 3、关闭资源try {searcher.close();} catch (IOException e) {throw new RuntimeException(e);}// 备注:并发使用,每个线程需要创建一个独立的 searcher 对象单独使用。}
xdb文件官网所在路径
xdb文件本地所在路径
maven
<!-- ip地址库 --><dependency><groupId>org.lionsoul</groupId><artifactId>ip2region</artifactId><version>2.6.4</version></dependency>
官网地址https://github.com/lionsoul2014/ip2region/tree/master/binding/java
学习ip2region相关推荐
- 准确率 99.9% 的离线IP地址定位库
点击关注公众号,利用碎片时间学习 Ip2region 是一个离线 IP 地址定位库,准确率高达 99.9%,搜索性能为 0.0x 毫秒.DB 文件只有几兆字节,其中存储了所有 IP 地址. 支持 Ja ...
- java入门 慕路径,Java入门基础知识总结学习教程大全【必看经典】
类型的表达式,是循环条件,表达式3是党执行了一遍循环之后,修改控制循环的变量值. ??? for语句的执行过程是这样的:首先计算表达式1,完成必要的初始化工作:然后判断表达式2的值,如果表达式的值为t ...
- Java EE学习心得
–Java EE学习心得 1. 称为编程专家的秘诀是: 思考-----编程--------思考------编程--.. 编程不能一步到位,不能一上来就编,必须先思考如何写,怎样写?然后再编程 ...
- FastAI 2019课程学习笔记 lesson 2:自行获取数据并创建分类器
文章目录 数据获取 google_images_download 的安装和使用 挂载google 个人硬盘到Google colab中 删除不能打开文件 创建ImageDataBunch 训练模型 解 ...
- FastAI 课程学习笔记 lesson 1:宠物图片分类
文章目录 代码解析 神奇的"%" 导入fastAI 库 下载解压数据集 untar_data 获取帮助文档 help() ? ?? doc 设置路径 get_image_files ...
- 深度学习学习指南-工具篇
colab Colab是由Google提供的云计算服务,通过它可以让开发者很方便的使用google的免费资源(CPU.GPU.TPU)来训练自己的模型. 学习经验总结 如何使用命令行? 通过!+cmd ...
- Redis学习之路(一)--下载安装redis
redis学习之路--下载安装redis windows安装redis 1.下载redis 2.安装 3.查看是否安装成功 windows安装redis 1.下载redis 网址:https://gi ...
- python内置库之学习configparser库(一)
python内置库之学习configparser库(一) 1.引言 ini文件简介 [节] 键=值 注:节不能重复出现 2.自己封装了一个增删改查的类,可以参考一下 import configpars ...
- 前端Vue学习之路(二)-Vue-router路由
Vue学习之路 (二) Vue-router(基础版) 一.增加静态路由 二.动态路由+路由嵌套+404页面 三. 编程式导航 四.命名路由 五.命名视图 六.重定向和起别名 1.重定向 2.起别名 ...
最新文章
- 测序技术及常见的有几种平台类型
- mysql+翻页性能,mysql 翻页优化
- JVM(3)——Java GC分析
- 深入Linux PAM体系结构
- linux系统层次(转)
- 今天,“场景赋能•驱动有数”,神策数据 2018 数据驱动大会在京成功举办
- mpvue还在维护吗_mpvue 微信小程序开发之生命周期
- Android 内存详细分析
- SAP Spartacus b2b 页面 popover append to body与否的不同行为
- 谷歌、阿里巴巴他们都来了,你呢?
- wikioi 1688 求逆序对
- 95-280-048-源码-资源管理-CPU
- 自己动手写Docker系列 -- 4.2使用AUFS包装busybox
- python学习之dict的items(),values(),keys()
- WPF/Sliverlight ScrollViewer与Panel(2)
- 编写程序,用户输入一个位以上的整数,输出其百位以上的数字。例如用户输入1234.则程序输出12.
- PHP与MySQL动态网站开发:第4版
- 华为存储IE证书挂靠
- VS2015自定义编程背景
- Prolog编程求解图搜索问题