Is constructor injection possible in Spring configuration classes?

大城市里の小女人 提交于 2019-12-02 01:08:15

There is a bug report about this limitation. It will be fixed with Spring 4.3.

Please note that another bug report (not fixed yet today fixed in 4.3-RC1) report a problem when using this very new feature and injecting generics in constructor of a @Configuration class.

In Spring 4.3, you can use org.springframework.beans.factory.ObjectProvider in @Configuration annotated class constructors to inject beans. for example:

@Configuration
public class SimpleBean {
  private final InnerBean prop1;
  public Simple Bean(ObjectProvider<InnerBean> innerBeanProvider) {
     prop1 = innerBeanProvider.getObject();
  }      
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!