Blade框架中新建业务服务,引入xxl-job,做为Executor时,会报循环依赖错误

Blade 未结 1 381
xwuyi
xwuyi 剑童 2023-11-16 16:30

一、该问题的重现步骤是什么?

1. 业务模块中,引入xxl-job-core后,初始化

XxlJobConfig类中

@Bean
public XxlJobSpringExecutor xxlJobExecutor() {
   logger.info(">>>>>>>>>>> xxl-job config init.");
   XxlJobSpringExecutor xxlJobSpringExecutor = new XxlJobSpringExecutor();
   xxlJobSpringExecutor.setAdminAddresses(adminAddresses);
   xxlJobSpringExecutor.setAppName(appname);
   xxlJobSpringExecutor.setIp(ip);
   xxlJobSpringExecutor.setPort(port);
   xxlJobSpringExecutor.setAccessToken(accessToken);
   xxlJobSpringExecutor.setLogPath(logPath);
   xxlJobSpringExecutor.setLogRetentionDays(logRetentionDays);

   return xxlJobSpringExecutor;
}

启动时会出现循环依赖报错,


The dependencies of some of the beans in the application context form a cycle:


┌──->──┐

|  xxlJobExecutor defined in class path resource [org/springblade/xpc/executor/config/XxlJobConfig.class]

└──<-──┘


2.看案例,加入了允许spring的循环依赖,如下


:
  :
    :


启动正常;



二、请问下blade框架,是做了什么会引起这样的错误?单看XxlJobConfig类的代码,很难理解会用循环依赖的问题,请指教谢谢


1条回答
  • 参考biz项目的例子。

    ~FG5(T67LYWR9J_3DKY]FTO.png

    作者追问:2023-11-16 17:48

    我看解决方式,是加spring配置 allow-circular-references: true


    但为什么blade框架会产生这样的问题,会不会有其它不可知的隐患?


    作者追问:2023-11-16 17:57

    而且看pom文件没意义,不是引用的问题,是blade框架的问题

    作者追问:2023-11-17 12:40

    因为bladex自带的例子也是引入了xxl-job-core,但是没有你说的这个错,

    所以不是bladex做了什么导致这个错,而是你引入了这个依赖外还做了哪些改动才导致的这个错。

    我们需要看到你具体的改动以及具体的依赖才好找原因。

    作者追问:2023-11-17 14:57

    如下截图,就blade的demo,我把允许spring循环依赖的给注释掉,也报循环依赖错误,所以还是框架那有问题


    image.png

    作者追问:2023-11-17 17:04

    注意看红框截图,删掉了所有的blade依赖,只保留最基础的4个非blade依赖,作为一个纯原生的springboot服务来看,依旧有这个错误,那么很显然了,是xxl-job本身的问题。

    因为blade的任何依赖都没有了也就是说不是blade的封装引起的。

    image.png

    image.png

    image.png

    作者追问:2023-11-17 17:06

    补充:xxlCofig的代码是拷贝xxljob官方demo的代码,加上循环依赖的配置后可以解决这个问题

    0 讨论(0)
提交回复