tomcat启动提示Couldn‘t get host name问题
作者:chgiser
tomcat启动提示Couldn‘t get host name
问题描述
系统之前是可以正常运行的,更新后启动tomcat报如下错误:
2020-07-31 17:21:39 [main] INFO org.quartz.impl.StdSchedulerFactory - Using default implementation for ThreadExecutor
2020-07-31 17:21:39 [main] ERROR org.quartz.impl.StdSchedulerFactory - Couldn't generate instance Id!
org.quartz.SchedulerException: Couldn't get host name!
at org.quartz.simpl.SimpleInstanceIdGenerator.generateInstanceId(SimpleInstanceIdGenerator.java:36)
at org.quartz.impl.StdSchedulerFactory.instantiate(StdSchedulerFactory.java:1235)
at org.quartz.impl.StdSchedulerFactory.getScheduler(StdSchedulerFactory.java:1559)
at org.springframework.scheduling.quartz.SchedulerFactoryBean.createScheduler(SchedulerFactoryBean.java:637)
at org.springframework.scheduling.quartz.SchedulerFactoryBean.afterPropertiesSet(SchedulerFactoryBean.java:511)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1765)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1702)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:579)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:501)
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:317)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:315)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:251)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1138)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1065)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:584)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:91)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:373)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1348)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:578)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:501)
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:317)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:315)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:204)
at org.springframework.context.support.PostProcessorRegistrationDelegate.registerBeanPostProcessors(PostProcessorRegistrationDelegate.java:238)
at org.springframework.context.support.AbstractApplicationContext.registerBeanPostProcessors(AbstractApplicationContext.java:710)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:535)
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:759)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:395)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:327)
at org.springframework.boot.web.servlet.support.SpringBootServletInitializer.run(SpringBootServletInitializer.java:155)
at org.springframework.boot.web.servlet.support.SpringBootServletInitializer.createRootApplicationContext(SpringBootServletInitializer.java:135)
at org.springframework.boot.web.servlet.support.SpringBootServletInitializer.onStartup(SpringBootServletInitializer.java:87)
at org.springframework.web.SpringServletContainerInitializer.onStartup(SpringServletContainerInitializer.java:172)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5125)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:713)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:690)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:695)
at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:978)
at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1850)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75)
at java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:112)
at org.apache.catalina.startup.HostConfig.deployWARs(HostConfig.java:773)
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:427)
at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1577)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:309)
at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:123)
at org.apache.catalina.util.LifecycleBase.setStateInternal(LifecycleBase.java:424)
at org.apache.catalina.util.LifecycleBase.setState(LifecycleBase.java:367)
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:929)
at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:831)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1377)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1367)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75)
at java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:134)
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:902)
at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:262)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
at org.apache.catalina.core.StandardService.startInternal(StandardService.java:423)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:928)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
at org.apache.catalina.startup.Catalina.start(Catalina.java:638)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:350)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:492)
Caused by: java.net.UnknownHostException: xxxxx: xxxxx: Name or service not known
at java.net.InetAddress.getLocalHost(InetAddress.java:1506)
at org.quartz.simpl.SimpleInstanceIdGenerator.generateInstanceId(SimpleInstanceIdGenerator.java:34)
... 76 common frames omitted
Caused by: java.net.UnknownHostException: xxxxx: Name or service not known
at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method)
at java.net.InetAddress$2.lookupAllHostAddr(InetAddress.java:929)
at java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1324)
at java.net.InetAddress.getLocalHost(InetAddress.java:1501)
... 77 common frames omitted
解决方案
如异常消息里所示,Couldn't get host name!, xxxxx: Name or service not known,可以推断是xxxxx这个hostname无法解析,将/etc/hosts文件打开,确实没有解析这个域名,添加一行域名解析:127.0.0.1 xxxxx
保存
然后重启tomcat,就可以正常启动了
后来跟运维人员确认了,他们确实中间调整过服务器的信息,导致了这个 hostname解析异常。。
关于Tomcat一些启动错误的解决
一、Eclipse tomcat 启动超时
错误内容: Server JBoss v4.0 at localhost was unable to start within 50 seconds. If the server requires more time, try increasing the timeout in the server editor
解决办法:修改路径
进入Eclipse的工作空间 .metadata.plugins\org.eclipse.wst.server.core目录,修改目录内文件server.xml
找到 start-timeout=”45” 并设高 start-timeout=”450”
二、eclipse无法加载tomcat
错误内容:删除tomcat后,重新导入tomcat,但无法加载tomcat
解决方案:
1.退出 eclipse
2.到[工程目录下]/.metadata/.plugins/org.eclipse.core.runtime
3.把org.eclipse.wst.server.core.prefs和org.eclipse.jst.server.tomcat.core.prefs这两个文件去掉
4.重启eclipse
三、tomcat运行没有生成class文件
错误内容: 项目编译没有生产class文件
解决方案:
1,选择: project->clean..->选第2个clean select project, 勾上start build immediatelly
2,如果项目里引了某个不用的jar包,而那个包又被你删了,就会出现不报错但怎么也编译不出来class文件的情况,可 以把所有包都删除,然后一个一个的再引入(需要的),不要一下子把所有包都引入来,没用的可能会引起不良后果.
步骤:选中项目——右键——Properties——选中下面红色区域——选中里面的Jar包——点remover
3,删除现在的项目,提前设置好编译文件输出路径,重新导入源文件,设置MyEclipse为保存时编译,然后在保存的时候就可以自动编译了,步骤:选中项目->点右键Properties->java build path->source->…/WEB-INF/src的output folder不要默认,编辑让它指向../WEB-INF/classes
4,再就是最重要的要看工程下面是否缺少了work目录,由于CVS控制时不把work加如版本,所以checkout后没有这个目录,要手工加上有的工程就能自动编译,最开始的时候,我只找到了前面7个方法,但是他们都没有解决我的问题.无意中我打开了”Problems”标签,发现里面说缺少work目录,手工加上,然后刷新项目就可以了..classpath这个xml文件要仔细看
四、tomcat启动 报 PermGen space
错误内容: 内存溢出
解决方案1:
1,重启tomcat
2,先停止运行,双击tomcat,打开Open launch configuration,然后 在Arguments中的VM arguments的编辑中的上面添加- Xms256M -Xmx1024M -XX:PermSize=64M -XX:MaxPermSize=128M,在重启就好了。
解决方案2: 设置Default VM Arguments,打开myeclipse—>windows —>preferences—>java—installed JREs
—>点击正在使用的JDK—>Edit—>Default VM Arguments 输 入-Xms64m -Xmx256m
五、tomcat启动 报 Address already in use: JVM_Bind”
错误内容: 8005端口被占用
解决方案一(推荐),修改tomcat/conf/server.xml文件
打开server.xml
将<Server port="8005" shutdown="SHUTDOWN">中8005改成不常用的端口号即可,比如9876
解决方案二,将占用8005的进程强行结束
(1) 在“运行”中输入CMD
(2)在启动的窗口中输入netstat -ano,就可以看到所有端口占用的情况,记下占用8005端口的程序的PID
(3)打开“任务管理器”,点击菜单栏的“查看”,再点击“选择列”,选上“PID(进程标识符)” 或者在cmd中输入tasklist命令,回车,查看
(4)在进程中找个相应的PID值,结束进程即可
总结
以上为个人经验,希望能给大家一个参考,也希望大家多多支持脚本之家。