spring @Service()中初始化方法怎么在@Service()的括号中表示。

2025-04-30 03:25:38
推荐回答(1个)
回答1:

你好,在方法上加上注解@PostConstruct 就可以了

@Service(value = "xxxServiceImpl")
public class XXXSerivceImpl {
@PostConstruct
//bean初始化之前调用的方法,等同于xml配置的init-method
public void init() {
......

}

}