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());
这样便可以读取了

相关文章:

  • 2021-12-03
  • 2021-11-23
  • 2021-11-23
  • 2021-11-23
  • 2021-11-01
  • 2018-09-03
  • 2021-11-23
  • 2018-12-27
猜你喜欢
  • 2020-07-08
  • 2021-08-08
  • 2021-08-27
  • 2020-10-03
  • 2018-04-09
  • 2019-09-26
  • 2020-10-09
  • 2019-10-28
相关资源
相似解决方案