其他分享
首页 > 其他分享> > SpringBoot启动失败报错,spring.profiles.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>**/*</include>
        </includes>
        <filtering>false</filtering>
    </resource>
</resources>

前提条件:

  1. 确保pom.xml配置文件<project></project>里已有环境变量配置:
<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配置文件<project></project>里已有打包插件:
<build>
	<plugins>
	    <plugin>
	        <groupId>org.springframework.boot</groupId>
	        <artifactId>spring-boot-maven-plugin</artifactId>
	        <configuration>
	            <includeSystemScope>true</includeSystemScope>
	        </configuration>
	    </plugin>
	</plugins>
</build>

标签:java,SpringBoot,spring,ScannerImpl,snakeyaml,yaml,报错,ParserImpl,org
来源: https://blog.csdn.net/fqfa1226/article/details/112684278