spring boot中static字段用@Value注解不进去解决方案

使用@Value注解static字段,会发现注解不上去,所以就有了下面这段代码。

package com.demo.test.utils;

import java.util.Random;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

@Component
public class ThreadPoolUtil {

    private static int corePoolSize;

    @SuppressWarnings("static-access")
    @Value("${threadpool.corepoolsize}")
    public void setCorePoolSize(int corePoolSize) {
        this.corePoolSize = corePoolSize;
    }

}

你可能感兴趣的:(Java,那些年踩过的坑)