🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
1. 初始化Bean ~~~ public interface InitializingBean { /** * Invoked by the containing {@code BeanFactory} after it has set all bean properties * and satisfied {@link BeanFactoryAware}, {@code ApplicationContextAware} etc. * <p>This method allows the bean instance to perform validation of its overall * configuration and final initialization when all bean properties have been set. * @throws Exception in the event of misconfiguration (such as failure to set an * essential property) or if initialization fails for any other reason */ void afterPropertiesSet() throws Exception; } ~~~ 1. 在factoryBean设置了它的所有属性值后,Bean可以实现的接口,**用来执行自定义初始化**,**也可以用来检查规定的属性值是否被赋值**。 2. 只有一个afterPropertiesSet方法,完成以上动作 3. 不能通过IOC注入的属性,例如只能通过new来创建的对象 ~~~ public class XxlJobAdminConfig implements InitializingBean, DisposableBean { @Value("${xxl.job.triggerpool.fast.max}") private int triggerPoolFastMax; @Resource private XxlJobInfoDao xxlJobInfoDao; @Override public void afterPropertiesSet() throws Exception { System.out.println(".....triggerPoolFastMax::" + triggerPoolFastMax); System.out.println(".....XxlJobInfoDao::" + xxlJobInfoDao); adminConfig = this; xxlJobScheduler = new XxlJobScheduler(); xxlJobScheduler.init(); } ~~~ 如下,在所有Bean的properties(由factory)被赋值后,执行afterPropertiesSet ``` .....triggerPoolFastMax::200 .....XxlJobInfoDao::org.apache.ibatis.binding.MapperProxy@56a4abd0 ```