SpringBoot的profile多环境切换
一、pom文件里面进行配置 profile和build
<!-- 环境 --> <profiles> <profile> <id>dev</id> <activation> <!--默认激活配置--> <activeByDefault>true</activeByDefault> </activation> <properties> <!--当前环境--> <profile.name>dev</profile.name> <!--Nacos配置中心地址--> <config.server-addr>127.0.0.1:8848</config.server-addr> <!--Nacos配置中心命名空间,用于支持多环境.这里必须使用ID,不能使用名称,默认为空--> <config.namespace>DEV</config.namespace> <!--Nacos服务发现地址--> <discovery.server-addr>127.0.0.1:8848</discovery.server-addr> <discovery.namespace>DEV</discovery.namespace> </properties> </profile> <profile> <id>test</id> <properties> <!--当前环境--> <profile.name>test</profile.name> <!--Nacos配置中心地址--> <config.server-addr>127.0.0.1:8848</config.server-addr> <!--Nacos配置中心命名空间,用于支持多环境.这里必须使用ID,不能使用名称,默认为空--> <config.namespace>TEST</config.namespace> <!--Nacos服务发现地址--> <discovery.server-addr>127.0.0.1:8848</discovery.server-addr> <discovery.namespace>TEST</discovery.namespace> </properties> </profile> <profile> <id>prod</id> <properties> <!--当前环境--> <profile.name>prod</profile.name> <!--Nacos配置中心地址--> <config.server-addr>127.0.0.1:8848</config.server-addr> <!--Nacos配置中心命名空间,用于支持多环境.这里必须使用ID,不能使用名称,默认为空--> <config.namespace>PROD</config.namespace> <!--Nacos服务发现地址--> <discovery.server-addr>127.0.0.1:8848</discovery.server-addr> <discovery.namespace>PROD</discovery.namespace> </properties> </profile> </profiles> <build> <resources> <resource> <directory>src/main/resources</directory> <!-- 处理文件时替换文件中的变量 --> <filtering>true</filtering> <excludes> <!-- 打包时排除文件,可自行添加test.yml --> <exclude>application.yml</exclude> <exclude>application-dev.yml</exclude> <exclude>application-test.yml</exclude> </excludes> </resource> <resource> <directory>src/main/resources</directory> <filtering>true</filtering> <!-- 打包时所包含得文件 --> <includes> <include>application.yml</include> <include>application-${profiles}.yml</include> </includes> </resource> </resources> </build>
二、创建三个文件 dev\test
三、bootstrap源文件内容
spring: profiles: active: test
四、bootstrap-dev内容
server: port: 8080 spring: profiles: dev
五、bootstrap-test内容
server: port: 8080 spring: profiles: test
六、切换
以上是SpringBoot的profile多环境切换怎么实现的详细内容。更多信息请关注PHP中文网其他相关文章!

Java在不同操作系统上的表现存在细微差异。1)JVM实现不同,如HotSpot、OpenJDK,影响性能和垃圾回收。2)文件系统结构和路径分隔符不同,需使用Java标准库处理。3)网络协议实现差异影响网络性能。4)GUI组件外观和行为在不同系统上有别。通过使用标准库和虚拟机测试,可减少这些差异的影响,确保Java程序稳定运行。

javaoffersrobustobject-IentiendedProgrammming(OOP)和Top-Notchsecurityfeatures.1)OopinjavainCludesClasses,对象,继承,多态性,和列出,andeclingfleximaintainablesys.ss.2)SecurityFeateTuersLudEtersludEterMachine(

JavaScriptandJavahavedistinctstrengths:JavaScriptexcelsindynamictypingandasynchronousprogramming,whileJavaisrobustwithstrongOOPandtyping.1)JavaScript'sdynamicnatureallowsforrapiddevelopmentandprototyping,withasync/awaitfornon-blockingI/O.2)Java'sOOPf

JAVAACHIEVESPLATFORMINDEPENTENCETHROUGHJAVAVIRTAILMACHINE(JVM)和BYTECODE.1)THEJVMINTERPRETSBBYTECODE,允许theingthesmecodetorunonanyanyanyanyplatformwithajvm.2)

Java'splatFormIndependecemeanSapplicationsCanrunonAnyPlatFormWithAjvm,使“ Writeonce,RunanyWhere”。

JVM'SperformanceIsCompetitiveWithOtherRuntimes,operingabalanceOfspeed,安全性和生产性。1)JVMUSESJITCOMPILATIONFORDYNAMICOPTIMIZAIZATIONS.2)c提供NativePernativePerformanceButlanceButlactsjvm'ssafetyFeatures.3)

JavaachievesPlatFormIndependencEthroughTheJavavIrtualMachine(JVM),允许CodeTorunonAnyPlatFormWithAjvm.1)codeisscompiledIntobytecode,notmachine-specificodificcode.2)bytecodeisisteredbytheybytheybytheybythejvm,enablingcross-platerssectectectectectross-eenablingcrossectectectectectection.2)

TheJVMisanabstractcomputingmachinecrucialforrunningJavaprogramsduetoitsplatform-independentarchitecture.Itincludes:1)ClassLoaderforloadingclasses,2)RuntimeDataAreafordatastorage,3)ExecutionEnginewithInterpreter,JITCompiler,andGarbageCollectorforbytec


热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

Video Face Swap
使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热门文章

热工具

WebStorm Mac版
好用的JavaScript开发工具

SublimeText3 Linux新版
SublimeText3 Linux最新版

MinGW - 适用于 Windows 的极简 GNU
这个项目正在迁移到osdn.net/projects/mingw的过程中,你可以继续在那里关注我们。MinGW:GNU编译器集合(GCC)的本地Windows移植版本,可自由分发的导入库和用于构建本地Windows应用程序的头文件;包括对MSVC运行时的扩展,以支持C99功能。MinGW的所有软件都可以在64位Windows平台上运行。

SublimeText3汉化版
中文版,非常好用

SublimeText3 Mac版
神级代码编辑软件(SublimeText3)