下面是我使用 Ehcache 2 在 AWS lambda 中缓存 Java 代码中的变量之一时出现的错误。 EhCache 是否在无服务器 Aws Lambda 上运行?
ERROR Unable to set localhost. This prevents creation of a GUID. Cause was: ip-10-22-209-10: ip-10-22-209-10: Name or service not known (net.sf.ehcache.Cache:224)
java.net.UnknownHostException: ip-10-22-209-10: ip-10-22-209-10: Name or service not known
at java.net.InetAddress.getLocalHost(InetAddress.java:1505)
at net.sf.ehcache.Cache.<clinit>(Cache.java:222)
at net.sf.ehcache.config.ConfigurationHelper.createCache(ConfigurationHelper.java:305)
at net.sf.ehcache.config.ConfigurationHelper.createCaches(ConfigurationHelper.java:238)
at net.sf.ehcache.CacheManager.addConfiguredCaches(CacheManager.java:816)
at net.sf.ehcache.CacheManager.doInit(CacheManager.java:498)
at net.sf.ehcache.CacheManager.init(CacheManager.java:394)
at net.sf.ehcache.CacheManager.<init>(CacheManager.java:269)
at net.sf.ehcache.CacheManager.newInstance(CacheManager.java:1103)
at net.sf.ehcache.CacheManager.newInstance(CacheManager.java:879)
at net.sf.ehcache.CacheManager.create(CacheManager.java:860)
at net.sf.ehcache.CacheManager.getInstance(CacheManager.java:894)
at com.capitalone.stsedh.datawise.engine.lite.core.service.RuleExecutionServiceImpl.<init>(RuleExecutionServiceImpl.java:50)
最佳答案
EHCache 使用本地计算机的 IP 地址作为(可疑)方式的一部分 construct a GUID (添加本地计算机的 IP 地址实际上并不比 128 位加密随机数更具全局唯一性,尤其是在许多服务器在私有(private) IP 上运行的世界中)。
虽然 Java 代码能够检索本地计算机的主机名,但 Lambda 无法解析该主机名。因此该信息不能在 GUID 中使用。
但是,解析 IP 失败不会导致 GUID 生成失败。日志消息来自 catch block看起来异常只是将 localhost
变量设置为 null
。因此生成的 GUID 将具有“null”而不是“10.22.209.10”。
关于amazon-web-services - 错误无法设置本地主机。这会阻止创建 GUID。在AWS lambda java代码中使用Ehcache时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48951387/