zoukankan      html  css  js  c++  java
  • static方法里用@Autowire或者@Resource注入的属性

    看代码先

    @Component//必须有,使当前类成为一个bean对象。
    public class CheckUntil {
        @Autowired
        private ReadApplicationUntil readApplicationUntil;
        private static ReadApplicationUntil readApplicationUntils;
    
    
        @PostConstruct
        public void init() {
            ReadApplicationUntils = readApplicationUntil;
        }
        public static boolean checkSignatures(String signature, String timestamp, String nonce) {
    
            String[] strings = new String[]{nonce, ReadApplicationUntils.getToken(), timestamp};
            Arrays.sort(strings);
            StringBuffer stringBuffer = new StringBuffer();
            for (String string : strings) {
                stringBuffer.append(string);
            }
            if (SHA1.encode(stringBuffer.toString()).equals(signature)) {
                return true;
            }
            return false;
        }
    }
    
    
    @Component要用到
    
    @Autowired
    private ReadApplicationUntil readApplicationUntil; 加载的类
    private static ReadApplicationUntil readApplicationUntils; static类
    

    要用到

    @PostConstruct//初始化的时候进行的操作注解
    public void init() {
        readApplicationUntils = readApplicationUntil;
        //这里需要把static类 和需要加载的类对调,就可以使用static加载readApplicationUntil对应的类方法了
         }
    

    @PostConstruct注解作用:Spring允许开发者在受管Bean中使用它。当DI容器实例化当前受管Bean时,@PostConstruct注解的方法会被自动触发,从而完成一些初始化工作,

    小白技术社
  • 相关阅读:
    js---小火箭回到顶部
    JS小案例--简单时钟
    堆排序以及TopK大顶堆小顶堆求解方式(js版)
    svg-icon
    Vue 点击按钮 触发 input file 选择文件
    图片裁剪放大缩小旋转 Cropper.js
    Cytoscape
    vue d3 force cytoscape
    获取当月多少天
    谷歌打印去页脚
  • 原文地址:https://www.cnblogs.com/xbjss/p/13326699.html
Copyright © 2011-2022 走看看