最近遇到一个问题,部署在服务器上的web项目启动的时候报错了
2019-05-17 11:33:03.796 [localhost-startStop-1] [INFO ] com.netinfosz.frame.quartz.bean.SchedulerFactoryBeanWithShutdownDelay Loading Quartz config from [ServletContext resource [/WEB-INF/conf/spring-quartz.properties]]
2019-05-17 11:33:03.833 [localhost-startStop-1] [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:1199)
at org.quartz.impl.StdSchedulerFactory.getScheduler(StdSchedulerFactory.java:1525)
at org.springframework.scheduling.quartz.SchedulerFactoryBean.createScheduler(SchedulerFactoryBean.java:595)
at org.springframework.scheduling.quartz.SchedulerFactoryBean.afterPropertiesSet(SchedulerFactoryBean.java:478)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1687)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1624)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:742)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:867)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:543)
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:443)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:325)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:107)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:5110)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5633)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1700)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1690)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.net.UnknownHostException: ZHBA-DB: ZHBA-DB: Name or service not known
at java.net.InetAddress.getLocalHost(InetAddress.java:1505)
at org.quartz.simpl.SimpleInstanceIdGenerator.generateInstanceId(SimpleInstanceIdGenerator.java:34)
... 27 common frames omitted
Caused by: java.net.UnknownHostException: ZHBA-DB: Name or service not known
at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method)
at java.net.InetAddress$2.lookupAllHostAddr(InetAddress.java:928)
at java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1323)
at java.net.InetAddress.getLocalHost(InetAddress.java:1500)
... 28 common frames omitted
2019-05-17 11:33:03.834 [localhost-startStop-1] [WARN ] org.springframework.web.context.support.XmlWebApplicationContext Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'schedulerFactoryBean' defined in class path resource [META-INF/config/spring/frame-quartz.xml]: Invocation of init method failed; nested exception is java.lang.IllegalStateException: Cannot run without an instance id.
- {dataSource-7} closed
- {dataSource-6} closed
- {dataSource-5} closed
- {dataSource-4} closed
- {dataSource-3} closed
- {dataSource-2} closed
- {dataSource-1} closed
开始的时候还以为是项目中的配置错了才导致的,跟定时器有关系,然后把定时器注释掉了,发现问题还是存在
经过百度查询了之后,发现是服务器的配置出了错误,当初搭建服务器的时候没注意到,有两个配置文件里面少了参数
第一个文件:HOSTS,路径:vi /etc/hosts
下添加主机名称 :ZHBA-DB
127.0.0.1 localhost ZHBA-DB
第二个文件
网卡配置 ifcfg-eth0, 路径 vi /etc/sysconfig/network-scripts/ifcfg-eth0
,添加以下参数
HOSTNAME=ZHBA-DB
然后项目正常启动完成