我想手动配置我的 picocontainer 为我的黄瓜构建配置配置对象的实例。IE,@ConfigurationProperties
在 Spring 中提供配置对象。
但是,目前尚不清楚如何做到这一点。该网站提供了大量关于如何操作容器的文档,但没有围绕这些示例的上下文。我正在使用 Cucumber maven 构建,使用cucumber-picocontainer
依赖项。
理想情况下,PicoContainer 将能够从主 yaml/ 配置文件(如 Spring)中获取依赖项,但如果我可以手动将它们输入到正在运行的容器中,那也可以。
为了清楚起见,我知道我可以这样做:
@RunWith(Cucumber.class)
public class RunWithCucumberTest{
public PicoContainer getContainer(){
MutablePicoContainer pico = new DefaultPicoContainer();
//do the config, inject onjects, etc
return pico;
}
}
但这并不意味着 this 返回的实例实际上是用来注入我的属性的。
总之,我正在寻找一种使用 pico 容器执行以下操作之一的方法:
- 自动能够创建配置类,通过文件(
yaml
,,properties
等)配置 - 手动配置正在运行的容器,自己从配置中创建对象并将它们交给 pico 稍后注入