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

SpringBoot入门之基本属性配置

2017-10-11 16:38 399 查看
方案1:在application.properties中配置server.port=8090   配置端口server.context-path=/girl  配置url前缀方案2:新建application.yml文件 在该文件中配置server:   port: 8089   context-path: /girl注意:语法 port: 8089  冒号后有一个空格示例:--------------------------------------------------------------------示例代码-----------------------------------------------------配置文件代码:application.yml文件server:   port: 8089   context-path: /girlgirl:  age: 18  name: A  content: "age: ${age}, name: ${name}"
GirlProperties类代码:
@Component@ConfigurationProperties(prefix = "girl")   //获取前缀是girl的配置public class GirlProperties {    private int age;    private String name;    private String  content;    public int getAge() {        return age;    }    public void setAge(int age) {        this.age = age;    }    public String getName() {        return name;    }    public void setName(String name) {        this.name = name;    }    public String getContent() {        return content;    }    public void setContent(String content) {        this.content = content;    }}----------------------------------------------------------------------------------------------------附:content: "age: ${age}, name: ${name}"    /*在配置中使用配置*/ @Value("${age}") private String age;      // 将配置文件中的内容注入到属性变量中@Component  注入配置@ConfigurationProperties(prefix = "girl")   //获取前缀是girl的配置 /*把配置写到一个类中*//**************************************************************************推荐观看廖师兄的2小时学会SpringBoot视频:点击打开链接我观看视频后写的一个简单的Demo:点击打开链接****************************************************************/
                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: