@ConfigurationProperties 获取不到配置文件属性值

@ConfigurationProperties 获取不到配置文件属性值

@Component
@ConfigurationProperties(prefix = “vehicle”)
public class VehicleConfig {

private static String name;
public static String getName() {
return name;
}
public static void setName(String name) {
VehicleConfig.name = name;
}
}

将set方法的静态static 去点即可,因为@ConfigurationProperties只会调用 非静态的set方法

public void setName(String name) {
VehicleConfig.name = name;
}

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