Springboot读取配置文件及其调用

配置文件类AppConfigTools

package com.example.tx_mini_pro.tools;

import lombok.Data;
import org.springframework.beans.factory.annotation.Value;

import org.springframework.stereotype.Component;

@Component

public class AppConfigTools {

    private static String wxAppId;

    private static String wxAppSecret;

    @Value("${wx.AppId}")
    public  void setWxAppId(String wxAppId) {
        AppConfigTools.wxAppId = wxAppId;
    }
    @Value("${wx.AppSecret}")
    public  void setWxAppSecret(String wxAppSecret) {
        AppConfigTools.wxAppSecret = wxAppSecret;
    }

    public static String getWxAppId() {
        return wxAppId;
    }

    public static String getWxAppSecret() {
        return wxAppSecret;
    }
}

对应的配置文件application.properties

Springboot读取配置文件及其调用_第1张图片

 

调用方式(任何地方)

String AppId=AppConfigTools.getWxAppId();
String AppSecret=AppConfigTools.getWxAppSecret();

你可能感兴趣的:(spring,boot,java,spring)