Skip to content

Commit cc23820

Browse files
committed
fixed registerResolvableDependency mechanism to correctly handle non-serializable factory objects (SPR-7264)
1 parent 5330dc4 commit cc23820

File tree

1 file changed

+10
-6
lines changed
  • org.springframework.beans/src/main/java/org/springframework/beans/factory/support

1 file changed

+10
-6
lines changed

org.springframework.beans/src/main/java/org/springframework/beans/factory/support/AutowireUtils.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2009 the original author or authors.
2+
* Copyright 2002-2010 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -136,11 +136,15 @@ public static boolean isSetterDefinedInInterface(PropertyDescriptor pd, Set<Clas
136136
* @return the resolved value
137137
*/
138138
public static Object resolveAutowiringValue(Object autowiringValue, Class requiredType) {
139-
if (autowiringValue instanceof ObjectFactory && !requiredType.isInstance(autowiringValue) &&
140-
autowiringValue instanceof Serializable && requiredType.isInterface()) {
141-
autowiringValue = Proxy.newProxyInstance(
142-
requiredType.getClassLoader(), new Class[] {requiredType},
143-
new ObjectFactoryDelegatingInvocationHandler((ObjectFactory) autowiringValue));
139+
if (autowiringValue instanceof ObjectFactory && !requiredType.isInstance(autowiringValue)) {
140+
ObjectFactory factory = (ObjectFactory) autowiringValue;
141+
if (autowiringValue instanceof Serializable && requiredType.isInterface()) {
142+
autowiringValue = Proxy.newProxyInstance(requiredType.getClassLoader(),
143+
new Class[] {requiredType}, new ObjectFactoryDelegatingInvocationHandler(factory));
144+
}
145+
else {
146+
return factory.getObject();
147+
}
144148
}
145149
return autowiringValue;
146150
}

0 commit comments

Comments
 (0)