spring boot配置文件格式 ${}和@@

${}和@@都是springboot引用属性变量的方式,具体区别与用法:

1、${}常用于pom.xml,和 src/main/resources/application.properties等默认配置文件的属性变量引用。

语法为:field_name=${field_value}

pom.xml示例:

xml 复制代码
<properties>
    <dubbo.version>2.7.0</dubbo.version>
</properties>
 
 <dependencies>
     <dependency>
         <groupId>org.apache.dubbo</groupId>
          <artifactId>dubbo</artifactId>
          <version>${dubbo.version}</version>
     </dependency>
 </dependencies>

application.properties示例:

logback日志配置

yaml 复制代码
log.config.address=classpath:config/logback-spring.xml
logging.config=${log.config.address}

2、@@ 方式常用于引用springboot非默认 配置文件(即其他配置文件)中的变量,是springboot为替代${}属性占位符产生,原因是${}会被maven处理,所以引用非默认配置文件时起不到引用变量的作用。

语法为:

yaml 复制代码
field_name=@field_value@

示例:在实际项目开发中,为了在不同环境进行测试,我们会在src/main/resources目录下创建config文件夹,并在config中创建多个properties文件,例如:local.properties, development.properties, production.properties,当我们在src/main/resources/application.properties文件中引用src/main/resources/config/local.properties的属性变量时,就要使用@@方式

端口配置

yaml 复制代码
server.port=@server.port.web@

logback日志配置

yaml 复制代码
logging.config=@logging.config@
相关推荐
小程序设计37 分钟前
【springboot+vue】高校迎新平台管理系统(源码+文档+调试+基础修改+答疑)
vue.js·spring boot·后端
波波烤鸭1 小时前
Spring Boot 原理与性能优化实战
spring boot·后端·性能优化
AppleWebCoder2 小时前
Java大厂面试实录:AIGC与虚拟互动场景下的微服务与AI落地(附知识详解)
java·spring boot·微服务·ai·消息队列·aigc·虚拟互动
齐 飞3 小时前
Spring Cloud Alibaba快速入门03-OpenFeign进阶用法
spring boot·后端·spring cloud
ss2734 小时前
基于Springboot + vue实现的高校大学生竞赛项目管理系统
vue.js·spring boot·后端
托比-马奎尔4 小时前
初识SpringBoot
java·spring boot·后端
孫治AllenSun5 小时前
【Springboot】介绍启动类和启动过程
java·spring boot·后端
励志码农9 小时前
JavaWeb 30 天入门:第二十三天 —— 监听器(Listener)
java·开发语言·spring boot·学习·servlet
哈喽姥爷13 小时前
Spring Boot---自动配置原理和自定义Starter
java·spring boot·后端·自定义starter·自动配置原理