Reputation: 445
I'm using maxmind GeoLite2-Country.mmdb in springboot 3.3. This what I did: I subscribed and got a maxmind free licence which I used to download the database with bellow command:
curl "https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-Country&license_key=HERE-MY-LICENCE&suffix=mmdb" -o GeoLite2-Country.mmdb
Then then I verified that the file is indeed in the classpath src/main/resources/maxmind/GeoLite2-Country.mmdb
and I added this to my gradle.build :
implementation 'com.maxmind.geoip2:geoip2:2.15.0'
Then I configured application.properties as below :
maxmind.geoip2.database=classpath:maxmind/GeoLite2-Country.mmdb spring.geolite2.filter-databases=false geoip2.database.path=/maxmind/GeoLite2-Country.mmdb geoip2.database=file:src/main/resources/maxmind/GeoLite2-Country.mmdb spring.geolocation.database-reader.file=classpath:maxmind/GeoLite2-Country.mmdb
Then I tried to get the file in below code:
@Value("classpath:maxmind/GeoLite2-Country.mmdb")
private String dblocation;
@Bean(name = "GeoIPCountry")
public DatabaseReader databaseReader() throws IOException, GeoIp2Exception {
System.out.println(dblocation);
final File resource = new File(this.getClass()
.getClassLoader()
.getResource(dblocation)
.getFile());
return new DatabaseReader.Builder(resource).build();
}
But I'm getting error:
Caused by: o.s.b.BeanInstantiationException: Failed to instantiate [com.maxmind.geoip2.DatabaseReader]: Factory method 'databaseReader' threw exception with message: Cannot invoke "java.net.URL.getFile()" because the return value of "java.lang.ClassLoader.getResource(String)" is null
I even tried to download the file from this github repo but the error message remains the same. I will be very gratefull to anyone who can help me solve this issue.
Upvotes: 1
Views: 63