@Override protected T postProcessInstance(T aggregate) { applicationContext.getAutowireCapableBeanFactory().configureBean(aggregate, prototypeBeanName); return aggregate; } };
for (Map.Entry<String, ComponentMethodInterceptable> entry : interceptableComponents.entrySet()) { Object bean = getTargetObject(entry.getValue()); beanFactory.configureBean(bean, entry.getKey());
@javax.inject.Singleton public class SomeSingleton { @PostConstruct void post() { ApplicationContext ctx = SpringApplicationContext.get(); AutowireCapableBeanFactory awcbf = ctx.getAutowireCapableBeanFactory(); awcbf.configureBean(this, "someSingleton"); } }
@Component @Scope("singleton") public class CarFactory { @Autowired private AutowireCapableBeanFactory autowireCapableBeanFactory; public Car create( Make make, Model model, Year year ) { Car car = new Car( make, model, year ); // this will apply the post processors including ones that might wrap the original bean // such as transaction interceptors etc. Car carProxy = Car.class.cast(autowireCapableBeanFactory.configureBean(car, "carBean")); return carProxy; } }
public void init(FilterConfig filterConfig) throws ServletException { ServletContext servletContext = filterConfig.getServletContext(); WebApplicationContext webApplicationContext = WebApplicationContextUtils.getWebApplicationContext(servletContext); AutowireCapableBeanFactory autowireCapableBeanFactory = webApplicationContext.getAutowireCapableBeanFactory(); autowireCapableBeanFactory.configureBean(this, BEAN_NAME); }
@Autowired // This will not work if the object is deserialized private transient DatabaseConnection db; @Override public void call(Iterator<Txn> txns) { ... // do some fance stuff getDb().store(txns); } private DatabaseConnection getDb() { if(db == null) { WebApplicationContext webApplicationContext = WebApplicationContextUtils.getWebApplicationContext(MySpringUtils.getServletContext()); AutowireCapableBeanFactory autowireCapableBeanFactory = webApplicationContext.getAutowireCapableBeanFactory(); autowireCapableBeanFactory.configureBean(this, "databaseConnection"); } return db; }
for (final Map.Entry<String, ComponentMethodInterceptable> entry : interceptableComponents.entrySet()) { final Object bean = getTargetObject(entry.getValue()); beanFactory.configureBean(bean, entry.getKey());
/** * Resolves a Spring managed bean with the given {@link Class} type from the Spring {@link BeanFactory}. * * It is assumed that the given typed bean is the only bean of this {@link Class} type. If more than 1 bean * of the given {@link Class} type is found, then the Spring {@link BeanFactory} will throw * a {@link org.springframework.beans.factory.NoUniqueBeanDefinitionException}. * * If the {@link BeanFactory} is an instance of {@link AutowireCapableBeanFactory}, then the returned bean * will also be configured. * * @param <T> {@link Class} type of the registered Spring managed bean. * @param beanType required {@link Class} type of the registered Spring managed bean. * @return a Spring managed bean instance for the given, required {@link Class} type, or {@literal null} * if no bean instance of the given, required {@link Class} type could be found. * @throws BeansException if the Spring manage bean of the required {@link Class} type could not be resolved. * @see #getBeanFactory() */ @SuppressWarnings("unchecked") protected <T> T resolveBean(Class<T> beanType) { BeanFactory beanFactory = getBeanFactory(); if (beanFactory instanceof AutowireCapableBeanFactory) { AutowireCapableBeanFactory autowiringBeanFactory = (AutowireCapableBeanFactory) beanFactory; NamedBeanHolder<T> beanHolder = autowiringBeanFactory.resolveNamedBean(beanType); return (T) autowiringBeanFactory.configureBean(beanHolder.getBeanInstance(), beanHolder.getBeanName()); } else { return beanFactory.getBean(beanType); } }
/** * Resolves a Spring managed bean with the given {@link Class} type from the Spring {@link BeanFactory}. * * It is assumed that the given typed bean is the only bean of this {@link Class} type. If more than 1 bean * of the given {@link Class} type is found, then the Spring {@link BeanFactory} will throw * a {@link org.springframework.beans.factory.NoUniqueBeanDefinitionException}. * * If the {@link BeanFactory} is an instance of {@link AutowireCapableBeanFactory}, then the returned bean * will also be configured. * * @param <T> {@link Class} type of the registered Spring managed bean. * @param beanType required {@link Class} type of the registered Spring managed bean. * @return a Spring managed bean instance for the given, required {@link Class} type, or {@literal null} * if no bean instance of the given, required {@link Class} type could be found. * @throws BeansException if the Spring manage bean of the required {@link Class} type could not be resolved. * @see #getBeanFactory() */ @SuppressWarnings("unchecked") protected <T> T resolveBean(Class<T> beanType) { BeanFactory beanFactory = getBeanFactory(); if (beanFactory instanceof AutowireCapableBeanFactory) { AutowireCapableBeanFactory autowiringBeanFactory = (AutowireCapableBeanFactory) beanFactory; NamedBeanHolder<T> beanHolder = autowiringBeanFactory.resolveNamedBean(beanType); return (T) autowiringBeanFactory.configureBean(beanHolder.getBeanInstance(), beanHolder.getBeanName()); } else { return beanFactory.getBean(beanType); } }
view = (ThymeleafReactiveView) beanFactory.configureBean(viewInstance, viewName); } else {
view = (AbstractThymeleafView) beanFactory.configureBean(viewInstance, viewName); } else {
view = (AbstractThymeleafView) beanFactory.configureBean(viewInstance, viewName); } else {
view = (AbstractThymeleafView) beanFactory.configureBean(viewInstance, viewName); } else {
view = (AbstractThymeleafView) beanFactory.configureBean(viewInstance, viewName); } else {
view = (AbstractThymeleafView) beanFactory.configureBean(viewInstance, viewName); } else {