자바 -- springboot 설정 도구 클래스 주입

653 단어 SpringBoot
1. 문서 내용
package com.vim.common.utils;

import com.vim.common.properties.WeixinConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

//1.   bean   
@Component
public class WeixinUtils {

    //2.     
    private static WeixinUtils weixinUtils;

    //3.     bean
    @Autowired
    private WeixinConfig config;

    //4.     
    @PostConstruct
    public void init() {
        weixinUtils = this;
    }
    
    //5.    
    public static void test(){
        String token = weixinUtils.config.getToken();
    }
}

좋은 웹페이지 즐겨찾기