SpringBoot @AutoConfigureAfter 注解

介绍了@AutoConfigureAfter注解的作用,即加载配置类后再加载当前类,其value为数组,常配合@import注解使用,使用import时需该类先被spring ioc加载,此注解必不可少,还提醒spring仅对spring.factory文件下的配置类排序。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

@AutoConfigureAfter 在加载配置的类之后再加载当前类
它的value 是一个数组 一般配合着**@import** 注解使用 ,在使用import时必须要让这个类先被spring ioc 加载好
所以@AutoConfigureAfter必不可少

@Configuration
public class ClassA {	//在加载DemoConfig之前加载ClassA类

}

@Configuration
@AutoConfigureAfter(ClassA.class)
@Import(ClassA.class)
public class DemoConfig {

}

@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.TYPE })
public @interface AutoConfigureAfter {

	/**
	 * The auto-configure classes that should have already been applied.
	 * @return the classes
	 */
	Class<?>[] value() default {};

	/**
	 * The names of the auto-configure classes that should have already been applied.
	 * @return the class names
	 * @since 1.2.2
	 */
	String[] name() default {};

}

注意: spring只对spring.factory文件下的配置类进行排序

评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值