微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

使用黄瓜弹簧合并属性文件

如何解决使用黄瓜弹簧合并属性文件

我们使用黄瓜 + 硒来促进 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.propertiesapplication.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 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?