您的位置:首页 > 编程语言 > Java开发

SpringBoot系列(二)SpringBoot 项目属性配置

2017-12-30 19:26 351 查看
本系列博客将学习开发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方法
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: