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@
相关推荐
wb0430720127 分钟前
使用 Java 开发 MCP 服务并发布到 Maven 中央仓库完整指南
java·开发语言·spring boot·ai·maven
nbwenren2 小时前
Springboot中SLF4J详解
java·spring boot·后端
helx822 小时前
SpringBoot中自定义Starter
java·spring boot·后端
rleS IONS3 小时前
SpringBoot获取bean的几种方式
java·spring boot·后端
R***z1014 小时前
Spring Boot 整合 MyBatis 与 PostgreSQL 实战指南
spring boot·postgresql·mybatis
赵丙双5 小时前
spring boot AutoConfiguration.replacements 文件的作用
java·spring boot
计算机学姐6 小时前
基于SpringBoot的兴趣家教平台系统
java·spring boot·后端·spring·信息可视化·tomcat·intellij-idea
bearpping7 小时前
Spring Boot + Vue 全栈开发实战指南
vue.js·spring boot·后端
__土块__8 小时前
一次 Spring Boot 自动装配机制源码走读:从误用 @Component 到理解 Bean 生命周期
spring boot·源码分析·自动装配·bean生命周期·@configuration·configurationclasspostprocessor·cglib代理
回到原点的码农10 小时前
Spring Boot 3.3.4 升级导致 Logback 之前回滚策略配置不兼容问题解决
java·spring boot·logback