`

java.net.UnknownHostException: localhost.localdomain: localhost.localdomain

 
阅读更多
Tomcat启动异常:


JARs from $CATALINA_HOME/lib or add the WebSocket JARs to the tomcat.util.scan.DefaultJarScanner.jarsToSkip property in $CATALINA_BASE/conf/catalina.properties. Note that the deprecated Tomcat 7 WebSocket API will be available.
2017-05-18 18:44:38,122 ERROR - com.jd.common.network.LocalHost[44] - init hostname error!
java.net.UnknownHostException: localhost.localdomain: localhost.localdomain
at java.net.InetAddress.getLocalHost(InetAddress.java:1402)
at com.jd.common.network.LocalHost.<clinit>(LocalHost.java:42)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:147)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:87)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:990)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:943)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:485)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBean(BeanDefinitionValueResolver.java:271)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:121)


参考http://stackoverflow.com/questions/1881546/inetaddress-getlocalhost-throws-unknownhostexception解决方案

1  查看host
命令 getent hosts 或 cat /etc/hosts

2 查看 localhost.localdomain 的地址

getent hosts localhost.localdomain

3 在/etc/hosts添加localhost.localdomain

127.0.0.1       localhost localhost.localdomain localhost4 localhost4.localdomain4
127.0.0.1       localhost localhost.localdomain localhost6 localhost6.localdomain6





运行Test.java代码,正常了

import java.net.InetAddress;
import java.net.UnknownHostException;


public class Test{


    public static void main(String[] args) {

         try {
            String hostName = InetAddress.getLocalHost().getHostName();
            System.out.println(hostName);
         } catch (UnknownHostException e) {
                 e.printStackTrace();
         }
    }

}
分享到:
评论

相关推荐

    Caused by: java.net.UnknownHostException: openapi.alipay.com

    Caused by: java.net.UnknownHostException: openapi.alipay.com

    linux系统下部署TOMCAT错误java.net.UnknownHostException bogon bogon

    linux系统下部署TOMCAT异常错误java.net.UnknownHostException :bogon: bogon 主要原因是主机映射原因 修改hosts文件即可

    linux系统下部署TOMCAT错误java.net.UnknownHostException bogon bogon.docx

    java.net.UnknownHostException(解决方案).md

    常见的问题

    项目源码-java网络五子棋游戏

    【项目源码】-java网络...import java.net.UnknownHostException; import java.sql.Time; import java.util.logging.Level; import java.util.logging.Logger; import javax.swing.JOptionPane; /** * 登录面板 *

    项目源码-java企业QQ项目

    import java.net.UnknownHostException; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java...

    ResidentialAreaMap:ResidentialAreaMap-android

    参考百度Java文档Android Studio模拟定位服务 (安装插件)无法从百度获取地图数据错误显示如下: java.net.UnknownHostException: Unable to resolve host "loc.map.baidu.com": No address associated with ...

    consul客户端本地开发

    例如,在Java应用中,可以使用官方提供的`consul-client`库,通过`Registration`对象设置服务信息并调用`AgentService.register()`方法。对于其他语言,也有相应的SDK或HTTP请求实现。 5. **健康检查** Consul支持...

    jmeter-plugins-manager-1.4.jar插件

    支持JMS(Java消息服务)协议,使得JMeter可以用于测试消息中间件的性能。 5. **Graph Results** 提供了丰富的图表组件,如响应时间和吞吐量图,帮助用户直观地理解测试结果。 四、注意事项 在使用Plugins ...

    java HashMapDemo.java

    java HashMapDemo.java

    DBeaver连接mysql数据库图文教程

    **DBeaver 连接 MySQL 数据库的详细步骤** DBeaver 是一款强大的数据库管理工具,因其免费、开源且支持多种数据库的特点,深受开发者和DBA的青睐。它提供了直观的用户界面,使得数据库的管理和操作变得更加简单。...

    解决linux找不到hostname的处理

    java.net.UnknownHostException: java: java: No address associated with hostname at java.net.InetAddress.getLocalHost(InetAddress.java:1475) at net.sf.ehcache.Cache.&lt;clinit&gt;(Cache.java:222) ``` 此...

    Linux操作文档

    java.net.UnknownHostException: localhost.localdomain: localhost.localdomain: 未知的名称或服务 ``` 问题通常是由于主机名解析不正确导致的。以下步骤可帮助解决此类问题: 1. **编辑`/etc/hosts`文件**:添加...

    Android错误解决方法大集合

    一、 android java.net.UnknownHostException: Unable to resolve host"...": No address associated 错误 该错误是 Android 开发中常见的错误,主要是由于网络连接未开启或 Manifest 文件未标明网络访问权限所致。...

    java、.net

    Java 和 .NET 是两个主要的软件开发平台,它们各自提供了丰富的工具和技术来构建各种类型的应用程序。这两个平台在很多方面都有交集,但也各有特点。 Java 是一种面向对象的编程语言,由Sun Microsystems(现在是...

    java网络编程示例

    import java.net.UnknownHostException; public class TCPClient { public static void main(String[] args) { try { Socket socket = new Socket("127.0.0.1",4444); OutputStream oStream = socket....

    ip6-java.zip

    7. **配置和属性**:Java系统属性如`java.net.preferIPv6Addresses`和`java.net.preferIPv4Stack`可以用来配置系统首选的IP版本。 8. **异常处理**:处理网络编程中常见的异常,如`UnknownHostException`, `...

    用java获取IP地址

    import java.net.UnknownHostException; public class NsLookup { public static void main(String[] args) { try { InetAddress address = InetAddress.getByName(args[0]); // 获取指定域名的InetAddress对象 ...

    TCP并发上传——java源码

    import java.net.UnknownHostException; public class ClientDemo { public static void main(String[] args) { try { InputStream in = new FileInputStream("D:\\Client"); byte[] buf = new byte[1024*1024...

    srping-cloud-alibaba-nacos-feign.zip

    Feign允许开发者通过接口定义来调用其他服务,提供了类似Java的注解方式来指定HTTP请求的路径、方法、参数等。 整合Nacos和Feign,可以让服务间的调用更加简洁和高效: 1. 引入Spring Cloud Alibaba Nacos Config和...

Global site tag (gtag.js) - Google Analytics