为什么java.net.UnknownHostException需要更改hosts文件? [英] Why does java.net.UnknownHostException require changes to the hosts file?
问题描述
关于此问题播放框架GUID 为什么我必须更改主机文件?在fedora中运行测试时遇到了类似的问题,该测试返回了以下错误
In regards to this question Play Framework GUID why do I have to change my hosts file? I was having a similar issue while running a test in fedora which returned the following error
[error] (*:testListeners) java.net.UnknownHostException: fedora: fedora: Name
or service not known
我添加了一行
127.0.0.1 localhost fedora
修复了我的/etc/hosts文件,但是为什么必须首先这样做呢?
to my /etc/hosts file, which fixed this, but why should this have to be done in the first place?
推荐答案
播放服务器加载EhCache.加载EhCache(特别是net.sf.ehcache.Cache
)时,它将尝试确定localhost的地址,该地址在创建GUID的进程中使用,该GUID标识已创建的缓存实例. EhCache通过调用InetAddress.getLocalHost()
来做到这一点.此方法会在您的主机文件中搜索与为本地计算机设置的主机名匹配的条目,如果找不到,则会抛出UnknownHostException
.
Play server loads EhCache. When EhCache is loaded (specifically net.sf.ehcache.Cache
) it attempts to determine the address for localhost which is used in a process to create GUIDs identifying the cache instances created. EhCache does this by calling InetAddress.getLocalHost()
. This method searches your host file for an entry matching the hostname set for the local machine, if it doesn't find one it throws an UnknownHostException
.
如所链接问题的答案所示,此修复程序是为本地主机名设置主机条目.
The fix, as demonstrated in an answer to the question you linked, is to set a host entry for the local hostname.
这篇关于为什么java.net.UnknownHostException需要更改hosts文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!