本系列博客将学习开发SpringBoot,快速开发项目
SpringBoot系列 (二):SpringBoot 项目属性配置
文档结构
- 项目内置属性
- 自定义属性
- ConfigurationProperties 配置
一、 项目内置属性
在application.properties中配置:
server.port=8080
server.context-path=/
或者在application.yml中配置:
二、自定义属性
helloWorld: spring boot hello
@Value("${helloWorld}")
private String helloWorld;
@RequestMapping("/helloWorld")
public String say(){
return helloWorld;
}
三、ConfigurationProperties 配置
mysql:
jdbcName: com.mysql.jdbc.Driver
dbUrl: jdbc:mysql://localhost:3306/db_boot
userName: root
@Component
@ConfigurationProperties(prefix="mysql")
public class MysqlProperties{
private String jdbcName;
private String dbUrl;
private String userName;
//省略get、set方法
}