spring 获取,打印环境变量
public static void main(String[] args) {
Map<String, String> env = System.getenv();
Set<Map.Entry<String, String>> entrySet = env.entrySet();
for(Map.Entry<String, String> entry : entrySet) {
System.out.println(entry.getKey() + " " + entry.getValue());
}
}
引入spring 解析配置文件的jar包
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
javaBean
/**
* 这里@ConfigurationProperties就是关键注解,需要上边引入的jar包支持
* prefix = "lc" 就是配置里的前缀,可以把前缀去掉,然后剩下后边的
* /
@Component
@ConfigurationProperties(prefix = "lc")
public class Test1 {
private String time;
public String getTime() {
return time;
}
public void setTime(String time) {
this.time = time;
}
}