Comments (5)
db废弃了,用 xdb,可以使用网络加载 xdb
from ip2region.
@lionsoul2014 多谢大佬的回答,辛苦了,有没有示例代码啊,还有个问题,每次都请求.xdb接口请求就很慢,有没有只用下载一次,后面就使用这个.xdb文件了,是不是性能更好点
from ip2region.
@lionsoul2014 我将文件下载到resource/ipdb/ip2region.xdb中,获取也成功了,
File file = ResourceUtils.getFile("classpath:ipdb/ip2region.xdb");
String dbPath = file.getPath();
Searcher searcher = null;
try {
searcher = Searcher.newWithFileOnly(dbPath);
} catch (IOException e) {
logger.info("searchIpAddr exception={}", e.getMessage());
}
但是,打包成docker镜像,发布到k8s之后就报错:
2023-08-29T07:53:50.323Z INFO 1 --- [or-http-epoll-2] c.s.u.controller.AccountController : --- login=class path resource [ipdb/ip2region.xdb] cannot be resolved to absolute file path because it does not reside in the file system: jar:file:/usr/local/users-service/app.jar!/BOOT-INF/classes!/ipdb/ip2region.xdb ---
我该如何处理呢?给个思路也行
from ip2region.
@lionsoul2014 我将文件下载到resource/ipdb/ip2region.xdb中,获取也成功了,
File file = ResourceUtils.getFile("classpath:ipdb/ip2region.xdb"); String dbPath = file.getPath(); Searcher searcher = null; try { searcher = Searcher.newWithFileOnly(dbPath); } catch (IOException e) { logger.info("searchIpAddr exception={}", e.getMessage()); }
但是,打包成docker镜像,发布到k8s之后就报错:
2023-08-29T07:53:50.323Z INFO 1 --- [or-http-epoll-2] c.s.u.controller.AccountController : --- login=class path resource [ipdb/ip2region.xdb] cannot be resolved to absolute file path because it does not reside in the file system: jar:file:/usr/local/users-service/app.jar!/BOOT-INF/classes!/ipdb/ip2region.xdb ---
我该如何处理呢?给个思路也行
看这个错误明显是文件加载的问题,要么放到外面机器上,要么cpr读取后使用
from ip2region.
try {
InputStream fileStream = new ClassPathResource("ipdb/ip2region.xdb").getInputStream();
searcher = Searcher.newWithBuffer(toByteArray(fileStream));
} catch (IOException e) {
logger.info("searchIpAddr exception={}", e.getMessage());
return ResponseEntity.ok(new ResultSuccess<>(null));
}
换成上面代码就ok了,非常感谢!
from ip2region.
Related Issues (20)
- 希望CSharp打包时不要将CHANGELOG.md打包进去 HOT 1
- 能支持IPv6吗 HOT 2
- 交流群地址在哪,找了半天没找到,只有一个公众号。 HOT 1
- 希望能更换HttpServlet相关的api到JarkataEE HOT 2
- 是否可以通过增加db大小来实现查询性能提高?
- 在springboot工程中,maven编译时,ip2region.db被重新编码
- nodejs 高并发查询 HOT 2
- [数据源更新] 最新数据 HOT 4
- region 为空,不同环境编译出来的可执行文件,mac 有值,ubuntu无值 HOT 1
- nginx 中 识别变量错误 HOT 1
- 能生成只有几个国家的IP段的数据文件吗? HOT 2
- Java中Searcher的loadVectorIndexFromFile方法的dbPath是必须要给到的吗 HOT 1
- 数据文件的文件生成时间可能会溢出
- [数据补充源] IP错误
- 请考虑出一个MAC地址查厂商的库
- 关于线程安全 HOT 2
- 调用偶现段错误问题 HOT 2
- txt 转 xdb 是报错 failed running genDb: java.lang.Exception: discontinuous data segment HOT 4
- 关于区域查询如何实现
- 关于 openresty 和 redis 的使用 HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ip2region.