Servlet/Portlet ApplicationContexts use a specific id based on servlet/portlet name; DefaultListableBeanFactory references are serializable now when initialized with an id; scoped proxies are serializable now, for web scopes as well as for singleton beans; injected request/session references are serializable proxies for the current request now

This commit is contained in:
Juergen Hoeller
2009-05-07 22:29:55 +00:00
parent 4ccb352aac
commit 266a65982d
26 changed files with 582 additions and 167 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2006 the original author or authors.
* Copyright 2002-2009 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,6 +16,8 @@
package org.springframework.aop.scope;
import java.io.Serializable;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.util.Assert;
@@ -32,7 +34,7 @@ import org.springframework.util.Assert;
* @see org.springframework.beans.factory.BeanFactory#getBean
* @see org.springframework.beans.factory.config.ConfigurableBeanFactory#destroyScopedBean
*/
public class DefaultScopedObject implements ScopedObject {
public class DefaultScopedObject implements ScopedObject, Serializable {
private final ConfigurableBeanFactory beanFactory;
@@ -43,8 +45,6 @@ public class DefaultScopedObject implements ScopedObject {
* Creates a new instance of the {@link DefaultScopedObject} class.
* @param beanFactory the {@link ConfigurableBeanFactory} that holds the scoped target object
* @param targetBeanName the name of the target bean
* @throws IllegalArgumentException if either of the parameters is <code>null</code>; or
* if the <code>targetBeanName</code> consists wholly of whitespace
*/
public DefaultScopedObject(ConfigurableBeanFactory beanFactory, String targetBeanName) {
Assert.notNull(beanFactory, "BeanFactory must not be null");

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2007 the original author or authors.
* Copyright 2002-2009 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -157,29 +157,6 @@ public abstract class AbstractBeanFactoryBasedTargetSource
this.beanFactory = other.beanFactory;
}
/**
* Replaces this object with a SingletonTargetSource on serialization.
* Protected as otherwise it won't be invoked for subclasses.
* (The <code>writeReplace()</code> 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 boolean equals(Object other) {

View File

@@ -16,6 +16,9 @@
package org.springframework.aop.target;
import java.io.NotSerializableException;
import java.io.ObjectStreamException;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanDefinitionStoreException;
import org.springframework.beans.factory.BeanFactory;
@@ -23,8 +26,8 @@ import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
/**
* Base class for dynamic TargetSources that can create new prototype bean
* instances to support a pooling or new-instance-per-invocation strategy.
* Base class for dynamic {@link TargetSource} implementations that create new prototype
* bean instances to support a pooling or new-instance-per-invocation strategy.
*
* <p>Such TargetSources must run in a {@link BeanFactory}, as it needs to
* call the <code>getBean</code> method to create a new prototype instance.
@@ -83,4 +86,32 @@ public abstract class AbstractPrototypeBasedTargetSource extends AbstractBeanFac
}
}
//---------------------------------------------------------------------
// Serialization support
//---------------------------------------------------------------------
/**
* Replaces this object with a SingletonTargetSource on serialization.
* Protected as otherwise it won't be invoked for subclasses.
* (The <code>writeReplace()</code> 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);
}
}
}