目录
@[TOC](springboot本机启动elasticjob抛出异常HostException(ip is null))
文章所属专区 项目问题解决
1.问题描述
springboot本机启动elasticjob抛出异常HostException(ip is null)
2.问题原因
- 异常信息中提到的"ip is null"可能是由于本机的IPV4在校验isReachable时返回false导致的1。这可能是因为使用了无线网导致IP验证问题。解决方法是引入Groovy依赖并在启动类中屏蔽org.apache.shardingsphere.elasticjob.infra.env.IpUtils.getIp()抛出的HostException异常。
- 另一个可能的原因是缺少依赖或配置错误。确保已正确引入elasticjob的依赖,并检查相关的配置是否正确。
- 还有一种可能是由于网络连接问题导致的。请确保网络连接正常,并尝试重新启动应用程序。
3.解决方案
1.使用的elasticjob版本为3.0.1
2.本机的IPV4在校验isReachable 返回false(可能是使用无线网,导致ip验证问题)
3.最后引入Groovy解决
- 引入包
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>2.4.15</version>
</dependency>
- 代码加入启动类
* 屏蔽org.apache.shardingsphere.elasticjob.infra.env.IpUtils.getIp()抛出
* HostException(ip is null) 的异常导致windows本地程序无法启动
*/
private static void shieldElasticjobIpIsNull(){
try {
IpUtils.getIp();
} catch (HostException e) {
//抛出HostException 且 异常信息为 "ip is null" 时,设置ip地址为 0.0.0.0
if("ip is null".equals(e.getMessage())){
String code = "org.apache.shardingsphere.elasticjob.infra.env.IpUtils.cachedIpAddress=\"0.0.0.0\";";
GroovyShell groovy = new GroovyShell();
groovy.evaluate(code);
}
}
}
4.reimport maven clean install 后启动正常
4.参考
[SpringBoot启动Tomcat失败:StandardEngine[Tomcat].StandardHost[localhost]
Apache ShardingSphere ElasticJob document
SpringBoot集成Elastic-job依赖注入bean失败
给个三连吧 谢谢谢谢谢谢了