首页 > 其他 > 详细

@PostConstruct注解

时间:2021-06-18 11:57:02      阅读:12      评论: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

 

@PostConstruct注解

原文:https://www.cnblogs.com/jiduoduo/p/14898389.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!