Linux启动jar包出现 quartz异常之:org.quartz.SchedulerException
异常如下:
1 |
2018-01-30 14:23:47.234 ERROR 6101 --- [main] org.quartz.impl.StdSchedulerFactory : Couldn't generate instance Id! |
1 2 3 4 5 6 7 |
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:1211) at org.quartz.impl.StdSchedulerFactory.getScheduler(StdSchedulerFactory.java:1519) at org.springframework.scheduling.quartz.SchedulerFactoryBean.createScheduler(SchedulerFactoryBean.java:597) at org.springframework.scheduling.quartz.SchedulerFactoryBean.afterPropertiesSet(SchedulerFactoryBean.java:480) ... |
1 2 3 4 |
Caused by: java.net.UnknownHostException: WLSHASRV007: WLSHASRV007: 域名解析暂时失败 at java.net.InetAddress.getLocalHost(InetAddress.java:1505) at org.quartz.simpl.SimpleInstanceIdGenerator.generateInstanceId(SimpleInstanceIdGenerator.java:34) ... 108 common frames omitted |
很糟糕,第一次碰到,查看了项目中的各处配置文件都没问题,最后 google 给我解决了,原来是 org.quartz.simpl.SimpleInstanceIdGenerator 中获取主机名异常了。
下面是源码:
1 2 3 4 5 6 7 8 9 |
public class SimpleInstanceIdGenerator implements InstanceIdGenerator { public String generateInstanceId() throws SchedulerException { try { return InetAddress.getLocalHost().getHostName() + System.currentTimeMillis(); } catch (Exception e) { throw new SchedulerException("Couldn't get host name!", e); } } } |
二、解决
其实解决是很简单,
① 查看主机名:
1 2 |
[[email protected] ~]# hostname WLSHASRV007 |
② 查看 hosts 文件(可以先使用 cat /etc/hosts进行查看),vi /etc/hosts ,确保无乱码等异常,并确认 127.0.0.1 后面有上命令查询出的主机名
③ 如图,发现没有,则添加即可