centOS 之 java.net.UnknownHostException: centos: centos: 未知的名稱或服務


  • 應用場景:啟動javaWeb項目時,報錯后終止。提示如下:

    Initializing EhCache CacheManager
    2019-10-21 22:36:20.486 ERROR 9783 --- [ main] net.sf.ehcache.Cache :
    Unable to set localhost. This prevents creation of a GUID. Cause was: centos: centos: 未知的名稱或服務

      java.net.UnknownHostException: centos: centos: 未知的名稱或服務
       at java.net.InetAddress.getLocalHost(InetAddress.java:1506) ~[na:1.8.0_231]
       at net.sf.ehcache.Cache.<clinit>(Cache.java:214) ~[ehcache-core-2.6.11.jar!/:na]
       at net.sf.ehcache.config.ConfigurationHelper.createCache(ConfigurationHelper.java:296) [ehcache-core-2.6.11.jar!/:na]
       at net.sf.ehcache.config.ConfigurationHelper.createDefaultCache(ConfigurationHelper.java:219) [ehcache-core-2.6.11.jar!/:na]
       at net.sf.ehcache.CacheManager.configure(CacheManager.java:722) [ehcache-core-2.6.11.jar!/:na]
    
  • 產生原因: 當前用戶未同 127.0.0.1建立映射關系

  • 解決辦法: 編輯hosts文件,將報錯名稱添加到127.0.0.1的映射中

      127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4  centos //此處添加centos
      ::1         localhost localhost.localdomain localhost6 localhost6.localdomain6


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM