[SpringBoot] @Value annotation reads configuration files to assign values to static variables

1. The class name is annotated with [@Component], for example:

@Component
public class DataFormatTaUtil {
    
    ...}

2. Static variable assignment:
[com.xianfeng.data.util.DataFormatTaUtil] is the class path

    /**
     * ta文件地址保存地址
     */
    private static String logBusFileAddress;

    /**
     * 静态变量logBusFileAddress赋值
     *
     * @param logBusFileAddress logBus日志文件上传地址
     * @return null
     */
    @Value("${spring.logBusFileAddress}")
    public void setLogBusFileAddress(String logBusFileAddress) {
    
    
        com.xianfeng.data.util.DataFormatTaUtil.logBusFileAddress = logBusFileAddress;
    }

3. After starting the project in this way, startup failure may occur. The reason is that the attribute in the configuration file is indented and the format is incorrect, which can be confirmed by assigning other attributes.

Guess you like

Origin blog.csdn.net/qq_42258975/article/details/110931278