Bean的春季黄瓜设置应用程序属性

时间:2019-08-06 20:03:13

标签: java spring spring-boot cucumber cucumber-java

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

0 个答案:

没有答案