Backend Development 4 min read

Integrate ip2region with Spring Boot Using the mica-ip2region Starter

This guide explains how to add the mica-ip2region starter to a Spring Boot project, covering Maven and Gradle dependencies, built‑in configuration, custom Maven settings for the ip2region.db file, bean injection, available lookup methods, and a complete service example.

Java Architecture Diary
Java Architecture Diary
Java Architecture Diary
Integrate ip2region with Spring Boot Using the mica-ip2region Starter

Introduction

mica-ip2region

is a starter wrapper for the open‑source

ip2region

project, designed to simplify usage for Spring Boot applications.

Usage

2.1 Maven

<code>&lt;dependency&gt;
  &lt;groupId&gt;net.dreamlu&lt;/groupId&gt;
  &lt;artifactId&gt;mica-ip2region&lt;/artifactId&gt;
  &lt;version&gt;${version}&lt;/version&gt;
&lt;/dependency&gt;</code>

2.2 Gradle

<code>compile("net.dreamlu:mica-ip2region:${version}")</code>

Configuration (built‑in, can be ignored)

Note

: mica automatically synchronizes the

ip2region.db

file, so manual configuration is usually unnecessary.

Configuration key

mica.ip2region.db-file-location

defaults to

classpath:ip2region/ip2region.db

, which points to the bundled database file.

Maven custom ip2region.db handling

When Maven copies resources, it applies a filter that can corrupt the binary

.db

file. Add the following plugin configuration to your

pom.xml

to prevent filtering:

<code>&lt;plugin&gt;
  &lt;artifactId&gt;maven-resources-plugin&lt;/artifactId&gt;
  &lt;configuration&gt;
    &lt;nonFilteredFileExtensions&gt;
      &lt;nonFilteredFileExtension&gt;db&lt;/nonFilteredFileExtension&gt;
    &lt;/nonFilteredFileExtensions&gt;
  &lt;/configuration&gt;
&lt;/plugin&gt;</code>

Documentation

4.1 Bean injection

<code>@Autowired
private Ip2regionSearcher regionSearcher;</code>

4.2 Method reference

<code>@Nullable
IpInfo memorySearch(long ip);
@Nullable
IpInfo memorySearch(String ip);
@Nullable
IpInfo getByIndexPtr(long ptr);
@Nullable
IpInfo binarySearch(long ip);
@Nullable
IpInfo binarySearch(String ip);
@Nullable
String getAddress(long ip);
@Nullable
String getAddress(String ip);
@Nullable
String getAddressAndIsp(long ip);
@Nullable
String getAddressAndIsp(String ip);
</code>

4.3 Example service

<code>public class Ip2regionServiceImpl implements IIp2regionService {
    @Autowired
    private Ip2regionSearcher regionSearcher;

    @Override
    public String getAddress(String ip) {
        return regionSearcher.getAddress(ip);
    }
}
</code>

About the mica component suite

The author maintains several open‑source projects under the mica suite, including mica-auto (Spring Boot starter utilities), mica (microservice component collection), and mica-mqtt (IoT MQTT component based on t‑io).

mica component diagram
mica component diagram
BackendJavaGradlemavenSpring Bootip2region
Java Architecture Diary
Written by

Java Architecture Diary

Committed to sharing original, high‑quality technical articles; no fluff or promotional content.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.