spring:lifecycle 优先级

1
2
3
4
5
public interface  {
void start();
void stop();
boolean isRunning();
}
1
2
3
4
public interface LifecycleProcessor extends  {
void onRefresh();
void onClose();
}

优先级

  1. 主键
  2. 接口实现
  3. 全局配置的方法名
    If multiple lifecycle mechanisms are configured for a bean, and each mechanism is configured with a different method name, then each configured method is executed in the order listed below. However, if the same method name is configured - for example,
    init() for an initialization method - for more than one of these lifecycle mechanisms,
    that method is executed once, as explained in the preceding section.

You can also use @Autowired for interfaces that are well-known resolvable dependencies:
BeanFactory , ApplicationContext , Environment , ResourceLoader ,
ApplicationEventPublisher , and MessageSource . These interfaces and their extended interfaces,
such as ConfigurableApplicationContext or ResourcePatternResolver , are automatically
resolved, with no special setup necessary