錯誤資訊
初看的時候還以為是端口占用: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 = 9991Exception 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" 刪除即可,程式碼如下:
@Beanpublic 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面試、資料結構、演算法等全套影片資料。
最新評論