本项目是手机号码转区域的SpringBoot自动配置
- 数据文件目录:点击查看
<dependency>
<groupId>cn.404z</groupId>
<artifactId>phone2region-spring-boot-autoconfigure</artifactId>
<version>2.2.1</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<version>2.7.15</version>
</dependency>
final String zdbPath = "E:/phone2region.zdb";
final int phone = 1875471;
// phone2region:
// resource-path: /file/phone2region/phone2region.zdb
log.info(String.valueOf(Phone2Region.parse(phone)));
log.info("是否已经初始化:{}", Phone2Region.initialized());
// INFO c.z.p.a.Phone2RegionAutoConfiguration : 手机号码转区域配置:资源路径RESOURCE_PATH /file/phone2region/phone2region.zdb
// INFO cn.z.phone2region.Phone2Region : 数据加载成功:版本号VERSION 20230225 ,校验码CRC32 C8AEEA0A
// INFO .z.p.a.Phone2RegionAutoConfigurationTest : Started Phone2RegionAutoConfigurationTest in 0.86 seconds (JVM running for 2.316)
// INFO .z.p.a.Phone2RegionAutoConfigurationTest : Region{province='山东', city='济宁', zipCode='272000', areaCode='0537', isp='移动'}
// INFO .z.p.a.Phone2RegionAutoConfigurationTest : 是否已经初始化:true
// phone2region:
// local-path: E:/phone2region.zdb
log.info(String.valueOf(Phone2Region.parse(phone)));
// INFO c.z.p.a.Phone2RegionAutoConfiguration : 手机号码转区域配置:本地路径LOCAL_PATH E:/phone2region.zdb
// INFO cn.z.phone2region.Phone2Region : 手机号码转区域初始化:文件路径LOCAL_PATH E:/phone2region.zdb
// INFO cn.z.phone2region.Phone2Region : 数据加载成功:版本号VERSION 20230225 ,校验码CRC32 C8AEEA0A
// INFO .z.p.a.Phone2RegionAutoConfigurationTest : Started Phone2RegionAutoConfigurationTest in 0.86 seconds (JVM running for 2.316)
// INFO .z.p.a.Phone2RegionAutoConfigurationTest : Region{province='山东', city='济宁', zipCode='272000', areaCode='0537', isp='移动'}
// phone2region:
// url-path: https://www.404z.cn/files/phone2region/v2.0.0/data/phone2region.zdb
log.info(String.valueOf(Phone2Region.parse(phone)));
// INFO c.z.p.a.Phone2RegionAutoConfiguration : 手机号码转区域配置:URL路径URL_PATH https://www.404z.cn/files/phone2region/v2.0.0/data/phone2region.zdb
// INFO cn.z.phone2region.Phone2Region : 手机号码转区域初始化:URL路径URL_PATH https://www.404z.cn/files/phone2region/v2.0.0/data/phone2region.zdb
// INFO cn.z.phone2region.Phone2Region : 数据加载成功:版本号VERSION 20230225 ,校验码CRC32 C8AEEA0A
// INFO .z.p.a.Phone2RegionAutoConfigurationTest : Started Phone2RegionAutoConfigurationTest in 0.86 seconds (JVM running for 2.316)
// INFO .z.p.a.Phone2RegionAutoConfigurationTest : Region{province='山东', city='济宁', zipCode='272000', areaCode='0537', isp='移动'}
// phone2region:
// resource-path: /file/phone2region/phone2region.zdb
// local-path: E:/phone2region.zdb
// url-path: https://www.404z.cn/files/phone2region/v2.0.0/data/phone2region.zdb
log.info(String.valueOf(Phone2Region.parse(phone)));
// INFO c.z.p.a.Phone2RegionAutoConfiguration : 手机号码转区域配置:资源路径RESOURCE_PATH /file/phone2region/phone2region.zdb
// INFO cn.z.phone2region.Phone2Region : 数据加载成功:版本号VERSION 20230225 ,校验码CRC32 C8AEEA0A
// INFO .z.p.a.Phone2RegionAutoConfigurationTest : Started Phone2RegionAutoConfigurationTest in 0.86 seconds (JVM running for 2.316)
// INFO .z.p.a.Phone2RegionAutoConfigurationTest : Region{province='山东', city='济宁', zipCode='272000', areaCode='0537', isp='移动'}
// # 不需要配置
log.info(String.valueOf(Phone2Region.parse(phone)));
// INFO .z.p.a.Phone2RegionAutoConfigurationTest : Started Phone2RegionAutoConfigurationTest in 0.86 seconds (JVM running for 2.316)
// cn.z.phone2region.Phone2RegionException: 未初始化!
// phone2region:
// resource-path: /file/phone2region/phone2region
log.info(String.valueOf(Phone2Region.parse(phone)));
// INFO c.z.p.a.Phone2RegionAutoConfiguration : 手机号码转区域配置:资源路径RESOURCE_PATH /file/phone2region/phone2region
// ERROR c.z.p.a.Phone2RegionAutoConfiguration : 资源文件异常!
// java.io.FileNotFoundException: class path resource [file/phone2region/phone2region] cannot be opened because it does not exist
// phone2region:
// resource-path: /file/phone2region/phone2region.zdb
Phone2Region.initByFile(zdbPath);
log.info(String.valueOf(Phone2Region.parse(phone)));
// INFO c.z.p.a.Phone2RegionAutoConfiguration : 手机号码转区域配置:资源路径RESOURCE_PATH /file/phone2region/phone2region.zdb
// INFO cn.z.phone2region.Phone2Region : 数据加载成功:版本号VERSION 20230225 ,校验码CRC32 C8AEEA0A
// INFO .z.p.a.Phone2RegionAutoConfigurationTest : Started Phone2RegionAutoConfigurationTest in 0.86 seconds (JVM running for 2.316)
// WARN cn.z.phone2region.Phone2Region : 已经初始化过了,不可重复初始化!
// INFO .z.p.a.Phone2RegionAutoConfigurationTest : Region{province='山东', city='济宁', zipCode='272000', areaCode='0537', isp='移动'}
更多请见测试