码农街博客

不忘初心,牢记使命

记docker-compose运行quartz job 出现 "Couldn't get host name!" 的问题

在部署分布式项目quartz-job模块中,启动时候报出以下错误:

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:1247)
        at org.quartz.impl.StdSchedulerFactory.getScheduler(StdSchedulerFactory.java:1579)
        at org.springframework.scheduling.quartz.SchedulerFactoryBean.createScheduler(SchedulerFactoryBean.java:677)
        at org.springframework.scheduling.quartz.SchedulerFactoryBean.prepareScheduler(SchedulerFactoryBean.java:614)
        at org.springframework.scheduling.quartz.SchedulerFactoryBean.afterPropertiesSet(SchedulerFactoryBean.java:502)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1863)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1800)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:620)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542)
        at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335)
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208)
        at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:276)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1380)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1300)
        at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.resolveFieldValue(AutowiredAnnotationBeanPostProcessor.java:656)
        at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:639)

Caused by: java.lang.IllegalStateException: Cannot run without an instance id.
        at org.quartz.impl.StdSchedulerFactory.instantiate(StdSchedulerFactory.java:1251)
        at org.quartz.impl.StdSchedulerFactory.getScheduler(StdSchedulerFactory.java:1579)
        at org.springframework.scheduling.quartz.SchedulerFactoryBean.createScheduler(SchedulerFactoryBean.java:677)
        at org.springframework.scheduling.quartz.SchedulerFactoryBean.prepareScheduler(SchedulerFactoryBean.java:614)
        at org.springframework.scheduling.quartz.SchedulerFactoryBean.afterPropertiesSet(SchedulerFactoryBean.java:502)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1863)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1800)

原因:

在docker-compose.yml中配置容器网络模式为“host”

network_mode: host

解决:

1.配置 /etc/hosts 设置一下当前主机的名称(即 hostname)


127.0.0.1   localhost   localhost.localdomain   your-hostname

2.去掉 network_mode: host 采用默认模式

点赞

本文标签: docker-composequartz

版权声明:本博客所有文章除特别声明外,本文皆为《githubwyj》原创,转载请保留文章出处。

本文链接:记docker-compose运行quartz job 出现 "Couldn't get host name!" 的问题 - https://www.mnjblog.cn/article/69