0


springboot中profiles.active的配置

1.application.yml改动

设置profiles.active 变量,添加不同环境的配置信息

2.pom文件修改

添加<profiles>节点内容

<profiles>
    <profile>
        <id>dev</id>
        <properties>
            <profiles.active>dev</profiles.active>
            <modifier>-dev</modifier>
        </properties>
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
    </profile>
    <!-- 测试环境 -->
    <profile>
        <id>test</id>
        <properties>
            <profiles.active>test</profiles.active>
            <modifier>-test</modifier>
        </properties>
    </profile>
    <!-- STAGE环境 -->
    <profile>
        <id>stage</id>
        <properties>
            <profiles.active>stage</profiles.active>
            <modifier>-stage</modifier>
        </properties>
    </profile>
    <!-- 生成环境 -->
    <profile>
        <id>prod</id>
        <properties>
            <profiles.active>prod</profiles.active>
            <modifier>-prod</modifier>
        </properties>
    </profile>
</profiles>

3.build节点修改

build节点下添加

<resources>
    <resource>
        <!--打包该目录下的 application.yml -->
        <directory>src/main/resources</directory>
        <!-- 启用过滤 即该资源中的变量将会被过滤器中的值替换 -->
        <filtering>true</filtering>
    </resource>
</resources>

PS:步骤三不做修改,可能造成启动失败。

10:30:22.666 [restartedMain] ERROR o.s.b.SpringApplication - [reportFailure,865] - Application run failed
org.yaml.snakeyaml.scanner.ScannerException: while scanning for the next token
found character '@' that cannot start any token. (Do not use @ for indentation)
in 'reader', line 8, column 13:
active: @profiles.active@
^

at org.yaml.snakeyaml.scanner.ScannerImpl.fetchMoreTokens(ScannerImpl.java:439)
 at org.yaml.snakeyaml.scanner.ScannerImpl.checkToken(ScannerImpl.java:248)
 at org.yaml.snakeyaml.parser.ParserImpl$ParseBlockMappingValue.produce(ParserImpl.java:633)
 at org.yaml.snakeyaml.parser.ParserImpl.peekEvent(ParserImpl.java:165)
 at org.yaml.snakeyaml.comments.CommentEventsCollector$1.peek(CommentEventsCollector.java:59)
 at org.yaml.snakeyaml.comments.CommentEventsCollector$1.peek(CommentEventsCollector.java:45)
 at org.yaml.snakeyaml.comments.CommentEventsCollector.collectEvents(CommentEventsCollector.java:140)
 at org.yaml.snakeyaml.comments.CommentEventsCollector.collectEvents(CommentEventsCollector.java:119)
 at org.yaml.snakeyaml.composer.Composer.composeScalarNode(Composer.java:221)
 at org.yaml.snakeyaml.composer.Composer.composeNode(Composer.java:191)
 at org.yaml.snakeyaml.composer.Composer.composeKeyNode(Composer.java:309)
 at org.yaml.snakeyaml.composer.Composer.composeMappingChildren(Composer.java:300)
 at org.yaml.snakeyaml.composer.Composer.composeMappingNode(Composer.java:288)
 at org.yaml.snakeyaml.composer.Composer.composeNode(Composer.java:195)
 at org.yaml.snakeyaml.composer.Composer.composeValueNode(Composer.java:313)
 at org.yaml.snakeyaml.composer.Composer.composeMappingChildren(Composer.java:304)
 at org.yaml.snakeyaml.composer.Composer.composeMappingNode(Composer.java:288)
 at org.yaml.snakeyaml.composer.Composer.composeNode(Composer.java:195)
 at org.yaml.snakeyaml.composer.Composer.composeValueNode(Composer.java:313)
 at org.yaml.snakeyaml.composer.Composer.composeMappingChildren(Composer.java:304)
 at org.yaml.snakeyaml.composer.Composer.composeMappingNode(Composer.java:288)
 at org.yaml.snakeyaml.composer.Composer.composeNode(Composer.java:195)
 at org.yaml.snakeyaml.composer.Composer.getNode(Composer.java:115)
 at org.yaml.snakeyaml.constructor.BaseConstructor.getData(BaseConstructor.java:135)
 at org.springframework.boot.env.OriginTrackedYamlLoader$OriginTrackingConstructor.getData(OriginTrackedYamlLoader.java:99)
 at org.yaml.snakeyaml.Yaml$1.next(Yaml.java:512)
 at org.springframework.beans.factory.config.YamlProcessor.process(YamlProcessor.java:198)
 at org.springframework.beans.factory.config.YamlProcessor.process(YamlProcessor.java:166)
 at org.springframework.boot.env.OriginTrackedYamlLoader.load(OriginTrackedYamlLoader.java:84)
 at org.springframework.boot.env.YamlPropertySourceLoader.load(YamlPropertySourceLoader.java:50)
 at org.springframework.boot.context.config.StandardConfigDataLoader.load(StandardConfigDataLoader.java:54)
 at org.springframework.boot.context.config.StandardConfigDataLoader.load(StandardConfigDataLoader.java:36)
 at org.springframework.boot.context.config.ConfigDataLoaders.load(ConfigDataLoaders.java:107)
 at org.springframework.boot.context.config.ConfigDataImporter.load(ConfigDataImporter.java:128)
 at org.springframework.boot.context.config.ConfigDataImporter.resolveAndLoad(ConfigDataImporter.java:86)
 at org.springframework.boot.context.config.ConfigDataEnvironmentContributors.withProcessedImports(ConfigDataEnvironmentContributors.java:116)
 at org.springframework.boot.context.config.ConfigDataEnvironment.processInitial(ConfigDataEnvironment.java:240)
 at org.springframework.boot.context.config.ConfigDataEnvironment.processAndApply(ConfigDataEnvironment.java:227)
 at org.springframework.boot.context.config.ConfigDataEnvironmentPostProcessor.postProcessEnvironment(ConfigDataEnvironmentPostProcessor.java:102)
 at org.springframework.boot.context.config.ConfigDataEnvironmentPostProcessor.postProcessEnvironment(ConfigDataEnvironmentPostProcessor.java:94)
 at org.springframework.boot.env.EnvironmentPostProcessorApplicationListener.onApplicationEnvironmentPreparedEvent(EnvironmentPostProcessorApplicationListener.java:102)
 at org.springframework.boot.env.EnvironmentPostProcessorApplicationListener.onApplicationEvent(EnvironmentPostProcessorApplicationListener.java:87)
 at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:176)
 at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:169)
 at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:143)
 at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:131)
 at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:82)
 at org.springframework.boot.SpringApplicationRunListeners.lambda$environmentPrepared$2(SpringApplicationRunListeners.java:63)
 at java.base/java.util.ArrayList.forEach(ArrayList.java:1541)
 at org.springframework.boot.SpringApplicationRunListeners.doWithListeners(SpringApplicationRunListeners.java:117)
 at org.springframework.boot.SpringApplicationRunListeners.doWithListeners(SpringApplicationRunListeners.java:111)
 at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:62)
 at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:375)
 at org.springframework.boot.SpringApplication.run(SpringApplication.java:333)
 at org.springframework.boot.SpringApplication.run(SpringApplication.java:1365)
 at org.springframework.boot.SpringApplication.run(SpringApplication.java:1354)
 at com.dojustek.PmsApplication.main(PmsApplication.java:18)
 at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
 at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
 at java.base/java.lang.reflect.Method.invoke(Method.java:566)
 at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49)

Process finished with exit code 0

标签: spring boot 后端 java

本文转载自: https://blog.csdn.net/scyshen/article/details/142377833
版权归原作者 scyshen 所有, 如有侵权,请联系我们删除。

“springboot中profiles.active的配置”的评论:

还没有评论