- SPRING_PROFILES_ACTIVE=prod,swagger
- SPRING_DATASOURCE_URL=jdbc:postgresql://samserver-postgresql:5432/samserver
- JHIPSTER_SLEEP=10 # gives time for the database to boot before the application
+ ports:
+ - 11000:11000
samserver-postgresql:
extends:
file: postgresql.yml
package com.samsung.samserver.config;
import com.maxmind.geoip2.DatabaseReader;
-import com.maxmind.db.CHMCache;
import com.maxmind.db.Reader;
+import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.*;
+import org.springframework.core.io.ResourceLoader;
+import org.slf4j.*;
import java.io.*;
/**
@Configuration
public class GeoIPConfiguration {
+ private static final Logger log = LoggerFactory.getLogger(GeoIPConfiguration.class);
+
+ @Autowired
+ private ResourceLoader resourceLoader;
+
@Bean
- public DatabaseReader geoReader() throws IOException {
+ public DatabaseReader geoReader() {
+ DatabaseReader databaseReader = null;
+ try {
+ log.info("trying to load geo database...");//NOSONAR
- return new DatabaseReader.Builder(
- new File(getClass().getClassLoader().getResource("geolite2/GeoLite2-City.mmdb").getFile()))
- .withCache(new CHMCache())
+ databaseReader = new DatabaseReader
+ .Builder(resourceLoader.getResource("classpath:geolite2/GeoLite2-City.mmdb").getInputStream())
.fileMode(Reader.FileMode.MEMORY)
.build();
+
+ log.info("database was loaded successfully.");//NOSONAR
+
+ } catch (IOException | NullPointerException e) {
+ log.error("database reader cound not be initialized. ", e);
+ }
+ return databaseReader;
}
}