正常从Spingboot中获取配置文件信息
@Value("${route.trace-info-provider.appKey}")
private String key;
取值时,有时这个key为NULL,可能原因有:
1.类没有加上@Component(或者@service等)
@Component
public class RouteApiUtils {
@Value("${route.trace-info-provider.appKey}")
private String key;
}
2.使用final或static修饰成员变量
@Component
public class RouteApiUtils {
@Value("${route.trace-info-provider.appKey}")
private static String key;
}
3.类被new新建了实例,而没有使用@Autowired
@Component
class RouteApiUtils{
@Value("${route.trace-info-provider.appKey}")
private String key;
}
class Test{
...
RouteApiUtils testValue = new RouteApiUtils()
本文探讨了在Springboot应用中,配置文件中${route.trace-info-provider.appKey}
8256

被折叠的 条评论
为什么被折叠?



