/** * Subclasses should call this method to create a new prototype instance. * @throws BeansException if bean creation failed */ protected Object newPrototypeInstance() throws BeansException { if (logger.isDebugEnabled()) { logger.debug("Creating new instance of bean '" + getTargetBeanName() + "'"); } return getBeanFactory().getBean(getTargetBeanName()); }
@Override public final void setBeanFactory(BeanFactory beanFactory) throws BeansException { super.setBeanFactory(beanFactory); try { createPool(); } catch (Throwable ex) { throw new BeanInitializationException("Could not create instance pool for TargetSource", ex); } }
/** * Replaces this object with a SingletonTargetSource on serialization. * Protected as otherwise it won't be invoked for subclasses. * (The {@code writeReplace()} method must be visible to the class * being serialized.) * <p>With this implementation of this method, there is no need to mark * non-serializable fields in this class or subclasses as transient. */ protected Object writeReplace() throws ObjectStreamException { if (logger.isDebugEnabled()) { logger.debug("Disconnecting TargetSource [" + this + "]"); } try { // Create disconnected SingletonTargetSource/EmptyTargetSource. Object target = getTarget(); return (target != null ? new SingletonTargetSource(target) : EmptyTargetSource.forClass(getTargetClass())); } catch (Exception ex) { String msg = "Cannot get target for disconnecting TargetSource [" + this + "]"; logger.error(msg, ex); throw new NotSerializableException(msg + ": " + ex); } }
@Override public void setBeanFactory(BeanFactory beanFactory) throws BeansException { super.setBeanFactory(beanFactory); // Check whether the target bean is defined as prototype. if (!beanFactory.isPrototype(getTargetBeanName())) { throw new BeanDefinitionStoreException( "Cannot use prototype-based TargetSource against non-prototype bean with name '" + getTargetBeanName() + "': instances would not be independent"); } }
/** * Replaces this object with a SingletonTargetSource on serialization. * Protected as otherwise it won't be invoked for subclasses. * (The {@code writeReplace()} method must be visible to the class * being serialized.) * <p>With this implementation of this method, there is no need to mark * non-serializable fields in this class or subclasses as transient. */ protected Object writeReplace() throws ObjectStreamException { if (logger.isDebugEnabled()) { logger.debug("Disconnecting TargetSource [" + this + "]"); } try { // Create disconnected SingletonTargetSource. return new SingletonTargetSource(getTarget()); } catch (Exception ex) { logger.error("Cannot get target for disconnecting TargetSource [" + this + "]", ex); throw new NotSerializableException( "Cannot get target for disconnecting TargetSource [" + this + "]: " + ex); } }
@Override public void setBeanFactory(BeanFactory beanFactory) throws BeansException { super.setBeanFactory(beanFactory); // Check whether the target bean is defined as prototype. if (!beanFactory.isPrototype(getTargetBeanName())) { throw new BeanDefinitionStoreException( "Cannot use prototype-based TargetSource against non-prototype bean with name '" + getTargetBeanName() + "': instances would not be independent"); } }
/** * Subclasses should call this method to destroy an obsolete prototype instance. * @param target the bean instance to destroy */ protected void destroyPrototypeInstance(Object target) { if (logger.isDebugEnabled()) { logger.debug("Destroying instance of bean '" + getTargetBeanName() + "'"); } if (getBeanFactory() instanceof ConfigurableBeanFactory) { ((ConfigurableBeanFactory) getBeanFactory()).destroyBean(getTargetBeanName(), target); } else if (target instanceof DisposableBean) { try { ((DisposableBean) target).destroy(); } catch (Throwable ex) { logger.warn("Destroy method on bean with name '" + getTargetBeanName() + "' threw an exception", ex); } } }
@Override public final void setBeanFactory(BeanFactory beanFactory) throws BeansException { super.setBeanFactory(beanFactory); try { createPool(); } catch (Throwable ex) { throw new BeanInitializationException("Could not create instance pool for TargetSource", ex); } }
public void setBeanFactory(BeanFactory beanFactory) throws BeansException { super.setBeanFactory(beanFactory); // Check whether the target bean is defined as prototype. if (beanFactory.isSingleton(getTargetBeanName())) { throw new BeanDefinitionStoreException( "Cannot use PrototypeBasedTargetSource against singleton bean with name '" + getTargetBeanName() + "': " + "instances would not be independent"); } }
/** * Replaces this object with a SingletonTargetSource on serialization. * Protected as otherwise it won't be invoked for subclasses. * (The {@code writeReplace()} method must be visible to the class * being serialized.) * <p>With this implementation of this method, there is no need to mark * non-serializable fields in this class or subclasses as transient. */ protected Object writeReplace() throws ObjectStreamException { if (logger.isDebugEnabled()) { logger.debug("Disconnecting TargetSource [" + this + "]"); } try { // Create disconnected SingletonTargetSource/EmptyTargetSource. Object target = getTarget(); return (target != null ? new SingletonTargetSource(target) : EmptyTargetSource.forClass(getTargetClass())); } catch (Exception ex) { String msg = "Cannot get target for disconnecting TargetSource [" + this + "]"; logger.error(msg, ex); throw new NotSerializableException(msg + ": " + ex); } }
/** * Subclasses should use this method to create a new prototype instance. */ protected Object newPrototypeInstance() throws BeansException { if (logger.isDebugEnabled()) { logger.debug("Creating new target from bean '" + getTargetBeanName() + "'"); } return getBeanFactory().getBean(getTargetBeanName()); }
public final void setBeanFactory(BeanFactory beanFactory) throws BeansException { super.setBeanFactory(beanFactory); try { createPool(beanFactory); } catch (BeansException ex) { throw ex; } catch (Exception ex) { throw new BeanInitializationException("Could not create instance pool", ex); } }
@Override public void setBeanFactory(BeanFactory beanFactory) throws BeansException { super.setBeanFactory(beanFactory); // Check whether the target bean is defined as prototype. if (!beanFactory.isPrototype(getTargetBeanName())) { throw new BeanDefinitionStoreException( "Cannot use prototype-based TargetSource against non-prototype bean with name '" + getTargetBeanName() + "': instances would not be independent"); } }
/** * Subclasses should call this method to create a new prototype instance. * @throws BeansException if bean creation failed */ protected Object newPrototypeInstance() throws BeansException { if (logger.isDebugEnabled()) { logger.debug("Creating new instance of bean '" + getTargetBeanName() + "'"); } return getBeanFactory().getBean(getTargetBeanName()); }
@Override public final void setBeanFactory(BeanFactory beanFactory) throws BeansException { super.setBeanFactory(beanFactory); try { createPool(); } catch (Throwable ex) { throw new BeanInitializationException("Could not create instance pool for TargetSource", ex); } }
/** * Subclasses should call this method to create a new prototype instance. * @throws BeansException if bean creation failed */ protected Object newPrototypeInstance() throws BeansException { if (logger.isDebugEnabled()) { logger.debug("Creating new instance of bean '" + getTargetBeanName() + "'"); } return getBeanFactory().getBean(getTargetBeanName()); }
/** * Subclasses should call this method to destroy an obsolete prototype instance. * @param target the bean instance to destroy */ protected void destroyPrototypeInstance(Object target) { if (logger.isDebugEnabled()) { logger.debug("Destroying instance of bean '" + getTargetBeanName() + "'"); } if (getBeanFactory() instanceof ConfigurableBeanFactory) { ((ConfigurableBeanFactory) getBeanFactory()).destroyBean(getTargetBeanName(), target); } else if (target instanceof DisposableBean) { try { ((DisposableBean) target).destroy(); } catch (Throwable ex) { logger.warn("Destroy method on bean with name '" + getTargetBeanName() + "' threw an exception", ex); } } }
/** * Subclasses should call this method to destroy an obsolete prototype instance. * @param target the bean instance to destroy */ protected void destroyPrototypeInstance(Object target) { if (logger.isDebugEnabled()) { logger.debug("Destroying instance of bean '" + getTargetBeanName() + "'"); } if (getBeanFactory() instanceof ConfigurableBeanFactory) { ((ConfigurableBeanFactory) getBeanFactory()).destroyBean(getTargetBeanName(), target); } else if (target instanceof DisposableBean) { try { ((DisposableBean) target).destroy(); } catch (Throwable ex) { logger.error("Couldn't invoke destroy method of bean with name '" + getTargetBeanName() + "'", ex); } } }