如何解决使用黄瓜弹簧合并属性文件
我们使用黄瓜 + 硒来促进 e2e 测试。我们正在使用以下依赖项来利用 Spring 依赖项注入。
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-spring</artifactId>
<version>6.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>5.2.6.RELEASE</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>5.2.6.RELEASE</version>
<scope>provided</scope>
</dependency>
然后我们使用这两个类来配置spring上下文
@ContextConfiguration(classes = SpringContextConfig.class)
@CucumberContextConfiguration
public class CucumberSpringConfiguration {
}
@PropertySource("application.properties")
@ComponentScan("com.example.e2e")
public class SpringContextConfig {
}
正如我们所见,我们的属性源被明确定义为指向给定文件。 有没有办法实现 Spring Boot 对配置文件和属性文件所做的“魔法”?
例如,当指定 -Dspring.profiles.active=dev
合并时,我希望 spring
application-dev.properties
和 application.properties
并给出最终的上下文属性。
解决方法
正如我们所见,我们的属性源被明确定义为指向给定文件。有没有办法实现 Spring Boot 对配置文件和属性文件所做的“魔法”?
Profile specific configuration files are a Spring Boot feature。因此,如果您使用的是 Spring Boot,这应该足以获取活动配置文件:
@SpringBootTest
@CucumberContextConfiguration
public class CucumberSpringConfiguration {
}
但是从您的依赖项来看,您似乎没有使用 Spring Boot。没有其他(简单的)方法可以使用特定于配置文件的配置文件。考虑将您的应用程序设为 Spring Boot 应用程序。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。