项目初始化EHcache CacheManager时报java.net.UnknownHostException异常
2017-05-07 16:15:48,865 [localhost-startStop-2] ERROR [net.sf.ehcache.Cache] - Unable to set localhost. This prevents creation of a GUID. Cause was: serv1.lin.vm.ncu: serv1.lin.vm.ncu: Name or service not knownjava.net.UnknownHostException: serv1.lin.vm.ncu: serv1.lin.vm.ncu: Name or service not known at java.net.InetAddress.getLocalHost(InetAddress.java:1475) at net.sf.ehcache.Cache.(Cache.java:214) at net.sf.ehcache.config.ConfigurationHelper.createCache(ConfigurationHelper.java:296) at net.sf.ehcache.config.ConfigurationHelper.createDefaultCache(ConfigurationHelper.java:219) at net.sf.ehcache.CacheManager.configure(CacheManager.java:722) at net.sf.ehcache.CacheManager.doInit(CacheManager.java:439) at net.sf.ehcache.CacheManager.init(CacheManager.java:377) at net.sf.ehcache.CacheManager. (CacheManager.java:259) at org.springframework.cache.ehcache.EhCacheManagerFactoryBean.afterPropertiesSet(EhCacheManagerFactoryBean.java:157) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1631)
查看hostname:
[root@serv1 bin]# hostname serv1 [root@serv1 bin]# hostname -i 未知的主机 在查看/etc/hosts [root@serv1bin]# vi /etc/hosts 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6解决方案: 其中没有hostname的映射,导致找不到主机。 ①修改hosts文件,添加主机的hostname即可: [root@serv1 bin]# vi /etc/hosts 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 127.0.0.1 serv1
② 重启主机 reboot -n
③ 重启tomcat服务