@PostConstruct注解

@PostConstruct注解

 

这个注解是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

 

@PostConstruct注解

上一篇:idea快捷键


下一篇:新版vscode(v1.57)必备配置项——文件标签栏换行展示;Edge集成调试