【问题标题】:Java Geoip2: Getting "java.lang.reflect.InvocationTargetException" ExceptionJava Geoip2:获取“java.lang.reflect.InvocationTargetException”异常
【发布时间】:2017-07-22 01:06:00
【问题描述】:

我在 Java 中使用 GeoIP2 将 IP 地址转换为来自 maxmind 数据库的位置信息。

我的java代码:

try {
    ClassLoader classLoader = getClass().getClassLoader();
    File database = new File(classLoader.getResource("GeoLite2-City.mmdb").getFile());

    DatabaseReader reader =  new DatabaseReader.Builder(database).build();
    InetAddress ipAddress = InetAddress.getByName(ip);
    CityResponse response = reader.city(ipAddress);

    City city = response.getCity();
    ...

} catch (UnknownHostException e) {
    logger.logError(getClass(), "getGeoIp", " transactionId:" + transactionId + " > " + e.getMessage(), null);
} catch (IOException e) {
    logger.logError(getClass(), "getGeoIp", " transactionId:" + transactionId + " > " + e.getMessage(), null);
} catch (GeoIp2Exception e) {
    logger.logError(getClass(), "getGeoIp", " transactionId:" + transactionId + " > " + e.getMessage(), null);
}

我在构建阅读器时收到java.lang.reflect.InvocationTargetException 异常。我认为杰克逊版本(2.5.3)与geoip2不兼容。但我无法修复。

我的依赖版本是:

<dependency>
    <groupId>com.maxmind.geoip2</groupId>
    <artifactId>geoip2</artifactId>
    <version>2.8.1</version>
</dependency>

<dependency>
    <groupId>org.codehaus.jackson</groupId>
    <artifactId>jackson-mapper-asl</artifactId>
    <version>1.9.13</version>
</dependency>   

【问题讨论】:

    标签: java jackson maxmind geoip2


    【解决方案1】:

    使用 2.3.0 版本的 geoip2。

    <dependency>
        <groupId>com.maxmind.geoip2</groupId>
        <artifactId>geoip2</artifactId>
        <version>2.3.0</version>
    </dependency>
    

    2.8.1 使用较新版本的 Jackson,导致与您的 Jackson 依赖项发生冲突。

    【讨论】:

      猜你喜欢
      • 2013-11-30
      • 2020-02-17
      • 1970-01-01
      • 2020-08-14
      • 2020-06-16
      • 1970-01-01
      • 2020-04-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多