Spring Boot 集成测试无法拾取默认配置文件,并在命令行未指定配置文件时引发错误

我正在尝试运行基于配置文件的测试。我已经在我的配置文件中设置了默认配置文件,但测试看不到它。SeleniumSpring Bootpom

不确定我是否缺少任何配置。

命令(执行测试):

  • mvn 测试 -Dspring.profiles.active=谷歌 - 工作正常

  • mvn 测试 - Dspring.profile.active=酱油实验室 - 工作正常

  • mvn 测试 - 错误(如下所示)

错误

Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder 'base.url' in value "${base.url}"

        at org.springframework.util.PropertyPlaceholderHelper.parseStringValue(PropertyPlaceholderHelper.java:172) ~[spring-core-5.0.10.RELEASE.jar:5.0.10.RELEASE]

        at org.springframework.util.PropertyPlaceholderHelper.replacePlaceholders(PropertyPlaceholderHelper.java:124) ~[spring-core-5.0.10.RELEASE.jar:5.0.10.RELEASE]

        at org.springframework.core.env.AbstractPropertyResolver.doResolvePlaceholders(AbstractPropertyResolver.java:237) ~[spring-core-5.0.10.RELEASE.jar:5.0.10.RELEASE]

        at org.springframework.core.env.AbstractPropertyResolver.resolveRequiredPlaceholders(AbstractPropertyResolver.java:211) ~[spring-core-5.0.10.RELEASE.jar:5.0.10.RELEASE]

        at org.springframework.context.support.PropertySourcesPlaceholderConfigurer.lambda$processProperties$0(PropertySourcesPlaceholderConfigurer.java:175) ~[spring-context-5.0.10.RELEASE.jar:5.0.10.RELEASE]

        at org.springframework.beans.factory.support.AbstractBeanFactory.resolveEmbeddedValue(AbstractBeanFactory.java:839) ~[spring-beans-5.0.10.RELEASE.jar:5.0.10.RELEASE]

qq_笑_17
浏览 90回答 2
2回答

青春有我

如果未指定任何截面梁,Spring 将激活默认截面梁。对于默认配置文件,它会扫描文件中的配置值。因此,您需要执行以下操作:application.properties创建文件application.properties加base.url=<url for default profile>之后,它应该工作正常。

侃侃无极

您需要启用资源筛选<build>&nbsp; &nbsp; <resources>&nbsp; &nbsp; &nbsp; &nbsp; <resource>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <directory>src/test/resources/</directory>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <filtering>true</filtering>&nbsp; &nbsp; &nbsp; &nbsp; </resource>&nbsp; &nbsp; </resources>&nbsp; &nbsp; <plugins>&nbsp; &nbsp; &nbsp; &nbsp; <plugin>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <groupId>org.springframework.boot</groupId>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <artifactId>spring-boot-maven-plugin</artifactId>&nbsp; &nbsp; &nbsp; &nbsp; </plugin>&nbsp; &nbsp; </plugins></build>
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java