我在配置类中定义了一个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 {
}