目前,在spring中,有很多方法可以初始化bean:
- 使用@PostConstruct注解
- 实现InitializingBean接口
1、使用@PostConstruct注解
@Service |
给需要初始化的方法添加注解@PostConstruct,以便它们能够初始化
2、实现InitializingBean接口
@Service |
实现InitializingBean接口并重写afterPropertiesSet方法,在该方法中可以完成初始化功能。
目前,在spring中,有很多方法可以初始化bean:
1、使用@PostConstruct注解
@Service |
给需要初始化的方法添加注解@PostConstruct,以便它们能够初始化
2、实现InitializingBean接口
@Service |
实现InitializingBean接口并重写afterPropertiesSet方法,在该方法中可以完成初始化功能。