GithubHelp home page GithubHelp logo

Comments (5)

lionsoul2014 avatar lionsoul2014 commented on June 9, 2024

db废弃了,用 xdb,可以使用网络加载 xdb

from ip2region.

zhangwei900808 avatar zhangwei900808 commented on June 9, 2024

@lionsoul2014 多谢大佬的回答,辛苦了,有没有示例代码啊,还有个问题,每次都请求.xdb接口请求就很慢,有没有只用下载一次,后面就使用这个.xdb文件了,是不是性能更好点

from ip2region.

zhangwei900808 avatar zhangwei900808 commented on June 9, 2024

@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.

ZJM6658 avatar ZJM6658 commented on June 9, 2024

@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.

zhangwei900808 avatar zhangwei900808 commented on June 9, 2024
image
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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.