来源网络
初看的时候还以为是端口占用:Address already in use: bind,不要被错误提示蒙蔽了,实则是 xxl-job 的执行器注解 @Bean 配置的问题。
2020-12-29 09:24:00.494 INFO 9284,// --- [ Thread-40] com.xxl.rpc.remoting.net.Server : >>>>>>>>>>> xxl-rpc remoting server start success, nettype = com.xxl.rpc.remoting.net.impl.netty_http.server.NettyHttpServer, port = 9991
Exception in thread "Thread-44" JAVA.net.BindException: Address already in use: bind
at sun.nio.ch.Net.bind0(Native Method)
at sun.nio.ch.Net.bind(Net.java:433)
at sun.nio.ch.Net.bind(Net.java:425)
at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:223)
at io.netty.channel.socket.nio.NIOServerSocketChannel.doBind(NioServerSocketChannel.java:134)
at io.netty.channel.AbstractChannel$AbstractUnsafe.bind(AbstractChannel.java:550)
at io.netty.channel.DefaultChannelPipeline$HeadContext.bind(DefaultChannelPipeline.java:1334)
at io.netty.channel.AbstractChannelHandlerContext.invokeBind(AbstractChannelHandlerContext.java:504)
at io.netty.channel.AbstractChannelHandlerContext.bind(AbstractChannelHandlerContext.java:489)
at io.netty.channel.DefaultChannelPipeline.bind(DefaultChannelPipeline.java:973)
at io.netty.channel.AbstractChannel.bind(AbstractChannel.java:248)
at io.netty.bootstrap.AbstractBootstrap$2.run(AbstractBootstrap.java:348)
at io.netty.util.concurrent.AbstractEventExecutor.safeExecute$$$capture(AbstractEventExecutor.java:164)
at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java)
at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:472)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:500)
at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:989)
at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
at java.lang.Thread.run(Thread.java:745)
12345678910111213141516171819202122
在低版本的 xxl-job 中, 初始化 XxlJobSpringExecutor 执行器需要在 @Bean 中加上 initMethod = "start", destroyMethod = "destroy"。
但是在高版本的 xxl-job(如 2.1.2)则需要删除 initMethod = "start", destroyMethod = "destroy"
报错前
@Bean(initMethod = "start", destroyMethod = "destroy")
public XxlJobSpringExecutor xxlJobExecutor() {
log.info(">>>>>>>>>>> xxl-job config init.");
XxlJobSpringExecutor xxlJobSpringExecutor = new XxlJobSpringExecutor();
xxlJobSpringExecutor.setAdminAddresses(jobProperties.getAdminAddresses());
xxlJobSpringExecutor.setAppName(jobProperties.getAppName());
xxlJobSpringExecutor.setPort(jobProperties.getPort());
xxlJobSpringExecutor.setLogPath(jobProperties.getLogPath());
xxlJobSpringExecutor.setLogRetentionDays(jobProperties.getLogRetentionDays());
xxlJobSpringExecutor.setIp(jobProperties.getIp());
xxlJobSpringExecutor.setAccessToken(jobProperties.getAccessToken());
return xxlJobSpringExecutor;
}
12345678910111213
把 @Bean 的属性 initMethod = "start", destroyMethod = "destroy" 删除即可,代码如下:
@Bean
public XxlJobSpringExecutor xxlJobExecutor() {
log.info(">>>>>>>>>>> xxl-job config init.");
XxlJobSpringExecutor xxlJobSpringExecutor = new XxlJobSpringExecutor();
xxlJobSpringExecutor.setAdminAddresses(jobProperties.getAdminAddresses());
xxlJobSpringExecutor.setAppName(jobProperties.getAppName());
xxlJobSpringExecutor.setPort(jobProperties.getPort());
xxlJobSpringExecutor.setLogPath(jobProperties.getLogPath());
xxlJobSpringExecutor.setLogRetentionDays(jobProperties.getLogRetentionDays());
xxlJobSpringExecutor.setIp(jobProperties.getIp());
xxlJobSpringExecutor.setAccessToken(jobProperties.getAccessToken());
return xxlJobSpringExecutor;
后台私信回复 1024 免费领取 SpringCloud、SpringBoot,微信小程序、Java面试、数据结构、算法等全套视频资料。