https://zhuanlan.zhihu.com/p/82223601
/config/application.properties
/application.properties
/src/main/resources/config/application.properties
/src/main/resources/application.properties
java -jar properties-0.0.1-SNAPSHOT.jar --spring.config.location=classpath:/javaboy/
https://blog.csdn.net/liuyueyi25/article/details/83244081
public class DemoController {
@Autowired
private Environment env;
env.getProperty("server.port"));
}
#方法二
@RestController
public class DemoController {
// 配置必须存在,且获取的是配置名为 app.demo.val 的配置信息
@Value("${app.demo.val}")
private String autoInject;
// 配置app.demo.not不存在时,不抛异常,给一个默认值data
@Value("${app.demo.not:dada}")
private String notExists;
}
#方法三 对象映射(子级)
@Data
@Component
@ConfigurationProperties(prefix = "app.proper")
public class ProperBean {
private String key;
private Integer id;
private String value;
}
https://mkyong.com/java/java-properties-file-examples/