@PostConstruct注解

时间:2021-06-18 19:42:28   收藏:0   阅读:0

技术图片

 

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

 

评论(0)
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!