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注解的方法会被自动触发,从而完成一些初始化工作,

    小白技术社
  • 相关阅读:
    Web.config配置详解
    vs2010下创建webservice
    WinForm如何调用Web Service
    Android动画的两种使用方式。
    ES6介绍
    django批量form表单处理
    django生命周期示意图
    django中的构造字典(二级菜单,评论树,购物车)
    django中介模型,CBV模型,及logging日志配制
    django中csrftoken跨站请求伪造的几种方式
  • 原文地址:https://www.cnblogs.com/xbjss/p/13326699.html
Copyright © 2011-2022 走看看