---
title: "ehcache报告UnknownHostException错误"
author: "harbey"
date: "2010-06-05T15:07:15Z"
tags: []
categories: ["编程语言"]
slug: "ehcache-unknownhostexception"
draft: false
lastmod: "2010-06-05T15:07:55Z"
id: 684773
url: "https://harbey.iteye.com/blog/684773"
---

报错如下：

```java

java.net.UnknownHostException: 主机名: 主机名
        at java.net.InetAddress.getLocalHost(InetAddress.java:1353)
        at net.sf.ehcache.Cache.<clinit>(Cache.java:145)
        at net.sf.ehcache.config.ConfigurationHelper.createCache(ConfigurationHelper.java:452)
        at net.sf.ehcache.config.ConfigurationHelper.createDefaultCache(ConfigurationHelper.java:368)
        at net.sf.ehcache.CacheManager.configure(CacheManager.java:321)
        at net.sf.ehcache.CacheManager.init(CacheManager.java:237)
        at net.sf.ehcache.CacheManager.<init>(CacheManager.java:210)
        at org.springframework.cache.ehcache.EhCacheManagerFactoryBean.afterPropertiesSet(EhCacheManagerFactoryBean.java:113)
        at or

```

原因：
encache源码：

```java

 static {
        try {
            localhost = InetAddress.getLocalHost();
        } catch (UnknownHostException e) {
            LOG.log(Level.SEVERE, "Unable to set localhost. This prevents creation of a GUID. Cause was: " + e.getMessage(), e);
        } catch (java.lang.NoClassDefFoundError e) {
            LOG.log(Level.FINE, "InetAddress is being blocked by your runtime environment. e.g. Google App Engine." +
                    " Ehcache will work as a local cache.");
        }
    }

```


解决办法：
 有可能是本地机器配置的域名解析Host配置有错误！！！我们应用中是这样引起的，也有可能是其他原因引起，要以实际情况为准！