xxljob问题排查

问题描述

xxljob自动注册失败, Ip地址为空, 查看日志发现XxlJobConfig中@Bean未加载
SpringBoot版本: 2.0.2.RELEASE

在这里插入图片描述

解决方案

在这里插入图片描述
使用以下两种配置方法均可

@Data
@Configuration
@ConfigurationProperties(prefix = "xxl.job")

== 

@Data
@ConfigurationProperties(prefix = "xxl.job") ---+
@EnableConfigurationProperties(XxlJobConfig.class) --- 需和 ① 配置在同一个类

原因分析

在之前的提交中, 在ABCDEFGConfig中使用了@EnableConfigurationProperties(XxlJobConfig.class), 后边业务变更删除了ABCDEFGConfig, 造成问题发生

查漏补缺

  • @Configuration 包含 @Component 注解, 会自动注入进 IOC 容器
  • @ConfigurationProperties 单独使用不会加载进 IOC 容器
  • @EnableConfigurationProperties 相当于把使用 @ConfigurationProperties 的类进行了一次注入

注意

@ConfigurationProperties(prefix = "a.b")
public class AConfig {
	private String c;
}


@Configuration
@EnableConfigurationProperties(AConfig.class)
public class BConfig {

}

配置不生效!!!

参考文章:
关与 @EnableConfigurationProperties 注解
spring boot 使用@ConfigurationProperties

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值