我需要在不传递构造函数参数的情况下,使用PicoContainer实现依赖注入,当前设置:
public class Shared_Data {
public Account_Pojo account_pojo;
public Shared_Data(Account_Pojo account_pojo) {
this.account_pojo = account_pojo;
}
在上面的示例中,我需要使用PicoContainer来实现DI,而无需传递:Account_Pojo account_pojo作为构造函数的参数,甚至可以吗?
我没有运气就尝试了以下方法:
public class Shared_Data {
public Account_Pojo account_pojo;
public Shared_Data() {
}
public void setAccount_pojo(Account_Pojo account_pojo) {
this.account_pojo = account_pojo;
}
public Account_Pojo getAccount_pojo() {
setAccount_pojo(account_pojo);
return account_pojo;
}
}
您可以使用SetterInjection
组件工厂[0]设置一个微微容器。
pico = new DefaultPicoContainer(new SetterInjection());
pico.addComponent(Account_Pojo.class);
这样的事情应该起作用。