我试图为我的春豆创建工厂类
public interface MyBean implements TBean{}
@Component
@Scope("prototype")
public class MyBeanImpl implements MyBean{
public MyBeanImpl(Request request){//..}
}
@Component
public class MyFactory {
public <T extends TBean> T createbean(Class<T> interfaceToCreate, Object... args) {
return (T)AppContext.getApplicationContext().getBean(interfaceToCreate, args);
}
}
方法AppContext.getApplicationContext()
返回ApplicationContext对象
在这里,我应该能够创建一个弹簧豆,如:
@Autowired
protected MyFactory factory;
Request myRequest;
void somemethod(){
factory.createbean(MyBean.class, myRequest)
}
但是BeanFactory 没有公开任何方法,例如:getBean(Class<T> clazz, Object... args)
而且我没有类的默认构造MyBeanImpl
函数
有谁知道如何做到这一点?