From cc238207f9153551ebc7e229a989b4027a287dd4 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Mon, 7 Jun 2010 18:08:44 +0000 Subject: [PATCH] fixed registerResolvableDependency mechanism to correctly handle non-serializable factory objects (SPR-7264) --- .../beans/factory/support/AutowireUtils.java | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/org.springframework.beans/src/main/java/org/springframework/beans/factory/support/AutowireUtils.java b/org.springframework.beans/src/main/java/org/springframework/beans/factory/support/AutowireUtils.java index 4d83d9c8e2..abdfa34180 100644 --- a/org.springframework.beans/src/main/java/org/springframework/beans/factory/support/AutowireUtils.java +++ b/org.springframework.beans/src/main/java/org/springframework/beans/factory/support/AutowireUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2009 the original author or authors. + * Copyright 2002-2010 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. @@ -136,11 +136,15 @@ abstract class AutowireUtils { * @return the resolved value */ public static Object resolveAutowiringValue(Object autowiringValue, Class requiredType) { - if (autowiringValue instanceof ObjectFactory && !requiredType.isInstance(autowiringValue) && - autowiringValue instanceof Serializable && requiredType.isInterface()) { - autowiringValue = Proxy.newProxyInstance( - requiredType.getClassLoader(), new Class[] {requiredType}, - new ObjectFactoryDelegatingInvocationHandler((ObjectFactory) autowiringValue)); + if (autowiringValue instanceof ObjectFactory && !requiredType.isInstance(autowiringValue)) { + ObjectFactory factory = (ObjectFactory) autowiringValue; + if (autowiringValue instanceof Serializable && requiredType.isInterface()) { + autowiringValue = Proxy.newProxyInstance(requiredType.getClassLoader(), + new Class[] {requiredType}, new ObjectFactoryDelegatingInvocationHandler(factory)); + } + else { + return factory.getObject(); + } } return autowiringValue; }