这个注解是java的,不是spring的。
Constructor(构造方法) -> @Autowired(依赖注入) -> @PostConstruct(注释的方法)
package com.example.studySpringBoot.util; import com.example.studySpringBoot.service.MyMethorClassService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import javax.annotation.PostConstruct; @Component public class MyUtils { private static MyUtils staticInstance = new MyUtils(); @Autowired private MyMethorClassService myService; @PostConstruct public void init(){ staticInstance.myService = myService; } public static Integer invokeBean(){ return staticInstance.myService.add(10,20); } }
转自:https://blog.csdn.net/qq360694660/article/details/82877222