SpringBoot使用自定义的properties

来源:互联网 发布:veleq电气仿真软件 编辑:程序博客网 时间:2024/06/05 05:51

自定义的是demo.properties,其中demo.name=李四

demo.id=1demo.name=\u674E\u56DB




package com.example.demo.bean;import org.springframework.beans.factory.annotation.Value;import org.springframework.context.annotation.PropertySource;import org.springframework.stereotype.Component;@Component//加入到ioc容器@PropertySource("classpath:demo.properties")//引入自己的propertiespublic class Demo {@Value("${demo.id}")private Integer id;@Value("${demo.name}")private String name;public Integer getId() {return id;}public void setId(Integer id) {this.id = id;}public String getName() {return name;}public void setName(String name) {this.name = name;}@Overridepublic String toString() {return "Demo [id=" + id + ", name=" + name + "]";}}