spring boot 读取配置文件

1、先创建配置文件application.properties,写上需要读取的属性
spring boot 读取配置文件
2、创建读取配置文件的类
spring boot 读取配置文件
注解:
@Configuration //读取配置文件并创建实例化bean,可以用@Component 注解代替
@PropertySource(value = {“classpath:config/application.properties”}) //配置文件路径
@ConfigurationProperties(prefix=“test”) //根据前缀读取配置文件

3、使用方式
@Autowired
private TestProperties testProperties;
System.out.print(testProperties.getProject_name());
这样便可以读取了