Skip to content

Instantly share code, notes, and snippets.

@circlee
Created June 30, 2020 07:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save circlee/c3cbf8f079d0268d0466f200c3a8c6d8 to your computer and use it in GitHub Desktop.
Save circlee/c3cbf8f079d0268d0466f200c3a8c6d8 to your computer and use it in GitHub Desktop.
public static Object resolveAutowiringValue(Object autowiringValue, Class<?> requiredType) {
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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment