Close

Spring Framework - ObjectProvider Examples

Spring Framework 

import org.springframework.beans.factory.ObjectProvider;
import org.springframework.beans.factory.annotation.Autowired;

public class MySingletonBean {

@Autowired
private ObjectProvider<MyPrototypeBean> myPrototypeBeanProvider;

public void showMessage() {
MyPrototypeBean bean = myPrototypeBeanProvider.getIfAvailable(
() -> new MyPrototypeBean("Default Bean"));
System.out.printf("%s, prototype instance id: %s%n",
bean.getMessage(), System.identityHashCode(bean));
}
}
Original Post




See Also