SpringBoot启动失败报错,spring.profiles.active:@env@中环境变量@无法识别报错_active: @env@

SpringBoot打包启动时无法识别到配置中的spring.profiles.active=@env@环境变量
报错内容如下:

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 3, column 13:
active: @env@
^

    at org.yaml.snakeyaml.scanner.ScannerImpl.fetchMoreTokens(ScannerImpl.java:419)
    at org.yaml.snakeyaml.scanner.ScannerImpl.checkToken(ScannerImpl.java:227)
    at org.yaml.snakeyaml.parser.ParserImpl$ParseBlockMappingValue.produce(ParserImpl.java:586)
    at org.yaml.snakeyaml.parser.ParserImpl.peekEvent(ParserImpl.java:158)
    at org.yaml.snakeyaml.parser.ParserImpl.checkEvent(ParserImpl.java:148)
    at org.yaml.snakeyaml.composer.Composer.composeNode(Composer.java:124)

解决方法:
pom.xml配置文件<project> <build>{添加内容}build>project>里添加resources配置:

<resources>
	<resource>
		<directory>src/main/resources</directory>
		<includes>
			<include>**/*
		
		true
	

前提条件:

  1. 确保pom.xml配置文件里已有环境变量配置:
<profiles>
    <profile>
        <id>dev</id>
        <properties>
            <env>dev</env>
        </properties>
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
    </profile>
    <profile>
        <id>test</id>
        <properties>
            <env>test</env>
        </properties>
    </profile>
    <profile>
        <id>prod</id>
        <properties>
            <env>prod</env>
        </properties>
    </profile>
</profiles>
  1. 确保pom.xml配置文件里已有打包插件:
<build>
    <plugins>
     <plugin>
     <groupId>org.springframework.boot</groupId>
     <artifactId>spring-boot-maven-plugin</artifactId>
     </plugin>
    </plugins>
</build>

你可能感兴趣的:(Spring-Boot,spring,spring,boot,后端)