Springboot3.5.x版本从环境变量加载属性

前言

Springboot3.5.x版本已经发布了,伴随着新属性的发型,能从环境变量加载属性

从环境变量加载属性

Springboot3.5.x版本之前,已经可以从环境变量加载单个属性,但现在,Spring Boot 3.5.x版本开始,可以从单个环境变量加载多个属性

备注: 本文使用的是window配置变量 1、进入到环境变量

2、然后在全局环境下配置

3、创建一个springboot3.5.x版本

4、配置环境变量

arduino 复制代码
spring.config.import=env:USER_CONFIGURATION

5、写一个获取配置变量接口

kotlin 复制代码
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
public class IndexController {


    @Value("${user.age}")
    private Integer age;

    @GetMapping("/hello")
    public Integer hello() {
        return age;
    }
}

6、启动程序

7、访问

http://localhost:8085/hello

结果如下图

备注: 如果idea已经启动了,而后配置的环境变量,要重启idea

总结

Springboot3.5.x版本已经发布了,而且伴随着一些新属性使用,可以在开发中使用,方便开发,不过看个人技术选型。Springboot4.0.0跟快也要发版

相关推荐
geovindu1 小时前
CSharp: Observer Pattern
开发语言·后端·观察者模式·设计模式·c#·.netcore·行为模式
Flynt2 小时前
把公司项目迁到 Spring Boot 4.0:编译通过只是开始
java·spring boot·后端
IT_陈寒2 小时前
Redis误用keys命令把生产环境搞崩了,血的教训
前端·人工智能·后端
Tangyuewei2 小时前
给老 Spring 项目装个 AI Agent
java·人工智能·spring
她的男孩2 小时前
多租户和数据权限怎么共存?扒完拦截器注册链路,我找到 4 个隐蔽的坑
java·后端·架构
用户8356290780512 小时前
使用 Python 设置 Excel 页眉和页脚
后端·python
步行cgn2 小时前
IoC 控制反转:从概念到 Spring 的实现
后端
爱勇宝3 小时前
没有 Fn 键关触控板?我做了一个双击即用的 Windows 小工具
前端·后端·程序员
沙湖遇雨3 小时前
8.ByteBuf 的数据模型、生命周期和内存分配
后端