Springboot2.1.5 Profile切换

木九天 发布于 2019/09/26 16:15
阅读 408
收藏 0

application.yml

spring:
  profiles:
    active: @spring.active@

pom.xml

<profiles>
    <profile>
        <id>local</id>
        <properties>
            <spring.active>local</spring.active>
        </properties>
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
    </profile>
    <profile>
        <id>dev</id>
        <properties>
            <spring.active>dev</spring.active>
        </properties>
    </profile>
</profiles>

然后启动报错:

Caused by: 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 17, column 13:
        active: @spring.active@

如果我加

"@spring.active@"

那么依旧报错为:

***************************
APPLICATION FAILED TO START
***************************

Description:

Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.

Reason: Failed to determine a suitable driver class

Action:

Consider the following:
    If you want an embedded database (H2, HSQL or Derby), please put it on the classpath.
    If you have database settings to be loaded from a particular profile you may need to activate it (no profiles are currently active).

Disconnected from the target VM, address: '127.0.0.1:58740', transport: 'socket'

Process finished with exit code 0

有分析到位的么?如果我直接用 local或者dev 代替@spring.active@就没事。

 

加载中
0
MONITE丶
MONITE丶
该评论暂时无法显示,详情咨询 QQ 群:912889742
木九天
木九天
我试过这个了,也是不行的,所有的配置我都加上了,不行,但是我重新弄了一个新的springboot项目,就可以,不知道哪里出现问题了
0
dongjunv5
dongjunv5
<profile>
            <id>dev</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <dependencies>
                <dependency>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-devtools</artifactId>
                    <optional>true</optional>
                </dependency>
            </dependencies>
            <properties>
                <!-- default Spring profiles -->
                <spring.profiles.active>dev</spring.profiles.active>
            </properties>
        </profile>

勾选maven dev profile,application-dev.yml 会覆盖application.yml

0
Joyzhou
Joyzhou
<plugin>
   <groupId>org.apache.maven.plugins</groupId>
   <artifactId>maven-resources-plugin</artifactId>
   <version>${maven-resources-plugin.version}</version>
   <configuration>
    <delimiters>
       <delimiter>@</delimiter>
    </delimiters>
   <useDefaultDelimiters>false</useDefaultDelimiters>
  </configuration>
</plugin>

yml 中使用单引号 '@spring.active@' 

如果parent是spring-boot-parent就不需要上述配置了

0
木九天
木九天

我试过这个了,也是不行的,所有的配置我都加上了,不行,但是我重新弄了一个新的springboot项目,就可以,不知道哪里出现问题了

OSCHINA
登录后可查看更多优质内容
返回顶部
顶部