diff --git a/src/main/java/org/springframework/data/projection/ProxyProjectionFactory.java b/src/main/java/org/springframework/data/projection/ProxyProjectionFactory.java index 1691df5d3..8d139f15c 100644 --- a/src/main/java/org/springframework/data/projection/ProxyProjectionFactory.java +++ b/src/main/java/org/springframework/data/projection/ProxyProjectionFactory.java @@ -27,7 +27,10 @@ import org.aopalliance.intercept.MethodInvocation; import org.springframework.aop.framework.Advised; import org.springframework.aop.framework.ProxyFactory; import org.springframework.beans.BeanUtils; +import org.springframework.context.ResourceLoaderAware; +import org.springframework.core.io.ResourceLoader; import org.springframework.util.Assert; +import org.springframework.util.ClassUtils; import com.fasterxml.jackson.annotation.JsonIgnore; @@ -41,11 +44,22 @@ import com.fasterxml.jackson.annotation.JsonIgnore; * @see SpelAwareProxyProjectionFactory * @since 1.10 */ -class ProxyProjectionFactory implements ProjectionFactory { +class ProxyProjectionFactory implements ProjectionFactory, ResourceLoaderAware { private static final boolean IS_JAVA_8 = org.springframework.util.ClassUtils.isPresent("java.util.Optional", ProxyProjectionFactory.class.getClassLoader()); + private ResourceLoader resourceLoader; + + /* + * (non-Javadoc) + * @see org.springframework.context.ResourceLoaderAware#setResourceLoader(org.springframework.core.io.ResourceLoader) + */ + @Override + public void setResourceLoader(ResourceLoader resourceLoader) { + this.resourceLoader = resourceLoader; + } + /* * (non-Javadoc) * @see org.springframework.data.rest.core.projection.ProjectionFactory#createProjection(java.lang.Object, java.lang.Class) @@ -73,7 +87,8 @@ class ProxyProjectionFactory implements ProjectionFactory { factory.addAdvice(new TargetClassAwareMethodInterceptor(source.getClass())); factory.addAdvice(getMethodInterceptor(source, projectionType)); - return (T) factory.getProxy(getClass().getClassLoader()); + return (T) factory + .getProxy(resourceLoader == null ? ClassUtils.getDefaultClassLoader() : resourceLoader.getClassLoader()); } /* @@ -143,7 +158,7 @@ class ProxyProjectionFactory implements ProjectionFactory { /** * Returns whether the given {@link PropertyDescriptor} describes an input property for the projection, i.e. a * property that needs to be present on the source to be able to create reasonable projections for the type the - * descritor was looked up on. + * descriptor was looked up on. * * @param descriptor will never be {@literal null}. * @return diff --git a/src/main/java/org/springframework/data/web/ProxyingHandlerMethodArgumentResolver.java b/src/main/java/org/springframework/data/web/ProxyingHandlerMethodArgumentResolver.java index 2f736f0e0..32e46fe5f 100644 --- a/src/main/java/org/springframework/data/web/ProxyingHandlerMethodArgumentResolver.java +++ b/src/main/java/org/springframework/data/web/ProxyingHandlerMethodArgumentResolver.java @@ -19,8 +19,10 @@ import org.springframework.beans.BeansException; import org.springframework.beans.MutablePropertyValues; import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.BeanFactoryAware; +import org.springframework.context.ResourceLoaderAware; import org.springframework.core.MethodParameter; import org.springframework.core.convert.ConversionService; +import org.springframework.core.io.ResourceLoader; import org.springframework.data.projection.SpelAwareProxyProjectionFactory; import org.springframework.web.bind.WebDataBinder; import org.springframework.web.bind.support.WebDataBinderFactory; @@ -34,7 +36,8 @@ import org.springframework.web.method.support.HandlerMethodArgumentResolver; * @author Oliver Gierke * @since 1.10 */ -public class ProxyingHandlerMethodArgumentResolver extends ModelAttributeMethodProcessor implements BeanFactoryAware { +public class ProxyingHandlerMethodArgumentResolver extends ModelAttributeMethodProcessor + implements BeanFactoryAware, ResourceLoaderAware { private final SpelAwareProxyProjectionFactory proxyFactory; private final ConversionService conversionService; @@ -61,6 +64,15 @@ public class ProxyingHandlerMethodArgumentResolver extends ModelAttributeMethodP this.proxyFactory.setBeanFactory(beanFactory); } + /* + * (non-Javadoc) + * @see org.springframework.context.ResourceLoaderAware#setResourceLoader(org.springframework.core.io.ResourceLoader) + */ + @Override + public void setResourceLoader(ResourceLoader resourceLoader) { + this.proxyFactory.setResourceLoader(resourceLoader); + } + /* * (non-Javadoc) * @see org.springframework.web.method.support.HandlerMethodArgumentResolver#supportsParameter(org.springframework.core.MethodParameter) diff --git a/src/main/java/org/springframework/data/web/config/SpringDataWebConfiguration.java b/src/main/java/org/springframework/data/web/config/SpringDataWebConfiguration.java index 413679654..644304c00 100644 --- a/src/main/java/org/springframework/data/web/config/SpringDataWebConfiguration.java +++ b/src/main/java/org/springframework/data/web/config/SpringDataWebConfiguration.java @@ -97,6 +97,11 @@ public class SpringDataWebConfiguration extends WebMvcConfigurerAdapter { argumentResolvers.add(sortResolver()); argumentResolvers.add(pageableResolver()); - argumentResolvers.add(new ProxyingHandlerMethodArgumentResolver(conversionService.getObject())); + ProxyingHandlerMethodArgumentResolver resolver = new ProxyingHandlerMethodArgumentResolver( + conversionService.getObject()); + resolver.setBeanFactory(context); + resolver.setResourceLoader(context); + + argumentResolvers.add(resolver); } }