1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
package com.yeshi.buwan.service.manager;
 
import com.yeshi.buwan.util.IPUtil;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Component;
 
@Component
public class IPManager {
 
    @Cacheable(value = "ipCache", key = "'getIPInfo-'+#ip")
    public IPUtil.IPInfo getIPInfo(String ip) throws Exception {
        IPUtil.IPInfo ipInfo = IPUtil.getIPInfo(ip);
        if (ipInfo == null) {
            throw new Exception("获取IP信息失败");
        }
        return ipInfo;
    }
 
}