java - Spring Cucumber 为 Bean 设置应用程序属性
问题描述
我在配置类中定义了一个 bean:
@Configuration
public class Config {
@Value("${some-property}")
private String someProperty;
@Bean
public SomeBean someBean() {
return new SomeBean(someProperty);
}
}
如何定义黄瓜步骤定义来设置属性some-property
并让其SomeBean
使用?
我面临的问题是我的 bean 在任何步骤发生之前就被初始化了。如何重新初始化 bean,或使用@RefreshScope
可能刷新?或者我可以在后面的步骤中启动/重新启动 spring 上下文吗?
黄瓜步骤:
@Given("I have some property set to (.*)")
public void someProperty(String someProperty) {
// Answer
}
这是启动 Spring Context 的空步骤定义类:
@SpringBootTest(classes = Application.class)
@DirtiesContext
@ActiveProfiles("it")
@AutoConfigureCache
@AutoConfigureTestEntityManager
@AutoConfigureWebMvc
@AutoConfigureMockMvc(secure = false)
@ImportAutoConfiguration
public class CucumberSpringContextBootstrapper implements En {
}
解决方案
推荐阅读
- java - 如何为纯 Java 应用程序启用 ProGuard 缩小?
- javascript - 使用特定关键字/字符串对数组进行排序
- .htaccess - .htaccess 重写 URL 而不更改
- java - 如何防止单击主页按钮进入主屏幕(跳板)?
- python - 为什么 Python 不对其进行二值化?
- python - 如何使用 pd.read_sas() 防止截断
- javascript - 节点使用带有 .catch() 语句的 Promise.all 为 Mongoose 请求抛出 UnhandledPromiseRejectionWarning
- web-crawler - Jsoup 下载错误。说必须登录,但没有登录
- python - 按值对字符串进行排序并添加到列表
- excel - Excel - 从受保护工作表的下拉列表中选择