为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

qq_笑_17 2022-09-22 10:30:05
我正在尝试运行基于配置文件的测试。我已经在我的配置文件中设置了默认配置文件,但测试看不到它。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]
查看完整描述

2 回答

?
青春有我

TA贡献1784条经验 获得超8个赞

如果未指定任何截面梁,Spring 将激活默认截面梁。对于默认配置文件,它会扫描文件中的配置值。因此,您需要执行以下操作:application.properties

  • 创建文件application.properties

  • base.url=<url for default profile>

之后,它应该工作正常。


查看完整回答
反对 回复 2022-09-22
?
侃侃无极

TA贡献2051条经验 获得超10个赞

您需要启用资源筛选


<build>

    <resources>

        <resource>

            <directory>src/test/resources/</directory>

            <filtering>true</filtering>

        </resource>

    </resources>

    <plugins>

        <plugin>

            <groupId>org.springframework.boot</groupId>

            <artifactId>spring-boot-maven-plugin</artifactId>

        </plugin>

    </plugins>

</build>


查看完整回答
反对 回复 2022-09-22
  • 2 回答
  • 0 关注
  • 88 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信