需求: 将pom.xml 文件中的版本号读取到配置文件并打印到日志中。

第一步: 在pom.xml 中添加以下标签。

  spring boot 项目从配置文件中读取maven 的pom.xml 文件标签的内容。

 

 

第二步: 将version 标签的值读取到配置文件中

spring boot 项目从配置文件中读取maven 的pom.xml 文件标签的内容。

 

这里使用 @@  而不是  ${}   是因为spring boot 无法识别配置文件中的 ${}  符号会导致报错。

第三步: 如果是在spring boot 默认配置文件中配置,那么就直接在项目中用 @Value 注解注入值即可。

  如果是自定义的配置文件,那么就使用 @PropertySource("classpath:fixed-config.properties")  注解来将加载自定义配置文件,然后使用  @Value 注解注入值即可

 

相关文章:

  • 2021-04-08
  • 2021-08-05
  • 2021-10-05
  • 2021-11-13
  • 2021-12-12
  • 2022-12-23
  • 2022-12-23
  • 2022-02-08
猜你喜欢
  • 2022-12-23
  • 2021-04-12
  • 2021-07-30
  • 2021-05-02
  • 2021-04-19
  • 2021-09-29
  • 2021-08-16
相关资源
相似解决方案