一个 Bean 同时使用了 @PostConstruct 方法、实现了 InitializingBean,并在 @Bean 上配置了 initMethod,三者的执行顺序是?

Spring / Java Web

  1. A.initMethod → afterPropertiesSet → @PostConstruct,自定义方法优先
  2. B.@PostConstruct → afterPropertiesSet → initMethod
  3. C.afterPropertiesSet → @PostConstruct → initMethod,接口回调优先
  4. D.按三个方法在源码中的声明位置从上到下依次执行