|
18 | 18 |
|
19 | 19 | import graphql.schema.DataFetchingEnvironment;
|
20 | 20 |
|
21 |
| -import org.springframework.beans.BeansException; |
22 |
| -import org.springframework.beans.factory.BeanClassLoaderAware; |
23 |
| -import org.springframework.beans.factory.BeanFactory; |
24 |
| -import org.springframework.beans.factory.BeanFactoryAware; |
| 21 | +import org.springframework.context.ApplicationContext; |
25 | 22 | import org.springframework.core.MethodParameter;
|
26 | 23 | import org.springframework.core.annotation.AnnotatedElementUtils;
|
27 | 24 | import org.springframework.data.projection.SpelAwareProxyProjectionFactory;
|
28 | 25 | import org.springframework.data.web.ProjectedPayload;
|
29 | 26 | import org.springframework.graphql.data.method.HandlerMethodArgumentResolver;
|
30 | 27 | import org.springframework.graphql.data.method.annotation.Argument;
|
| 28 | +import org.springframework.util.Assert; |
31 | 29 |
|
32 | 30 | /**
|
33 | 31 | * Resolver to obtain an {@link ProjectedPayload @ProjectedPayload},
|
|
58 | 56 | * @author Mark Paluch
|
59 | 57 | * @since 1.0.0
|
60 | 58 | */
|
61 |
| -public class ProjectedPayloadMethodArgumentResolver implements HandlerMethodArgumentResolver, |
62 |
| - BeanFactoryAware, BeanClassLoaderAware { |
| 59 | +public class ProjectedPayloadMethodArgumentResolver implements HandlerMethodArgumentResolver { |
63 | 60 |
|
64 | 61 | private final SpelAwareProxyProjectionFactory projectionFactory = new SpelAwareProxyProjectionFactory();
|
65 | 62 |
|
66 | 63 |
|
67 |
| - @Override |
68 |
| - public void setBeanFactory(BeanFactory beanFactory) throws BeansException { |
69 |
| - this.projectionFactory.setBeanFactory(beanFactory); |
70 |
| - } |
71 |
| - |
72 |
| - @Override |
73 |
| - public void setBeanClassLoader(ClassLoader classLoader) { |
74 |
| - this.projectionFactory.setBeanClassLoader(classLoader); |
| 64 | + /** |
| 65 | + * Create a new {@link ProjectedPayloadMethodArgumentResolver} using the given context. |
| 66 | + * @param applicationContext the {@link ApplicationContext} to use for bean lookup and class loading |
| 67 | + */ |
| 68 | + public ProjectedPayloadMethodArgumentResolver(ApplicationContext applicationContext) { |
| 69 | + Assert.notNull(applicationContext, "ApplicationContext must not be null"); |
| 70 | + this.projectionFactory.setBeanFactory(applicationContext); |
| 71 | + ClassLoader classLoader = applicationContext.getClassLoader(); |
| 72 | + if(classLoader != null) { |
| 73 | + this.projectionFactory.setBeanClassLoader(classLoader); |
| 74 | + } |
75 | 75 | }
|
76 | 76 |
|
77 | 77 |
|
|
0 commit comments