Skip to content

Commit f28d3dc

Browse files
committed
Initialize ProjectedPayloadMethodArgumentResolver with ApplicationContext
We now initialize the argument resolver with a context instead of relying on …Aware callbacks that are not supported by AnnotatedControllerConfigurer. Closes gh-333
1 parent 4653e94 commit f28d3dc

File tree

2 files changed

+17
-17
lines changed

2 files changed

+17
-17
lines changed

spring-graphql/src/main/java/org/springframework/graphql/data/method/annotation/support/AnnotatedControllerConfigurer.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,20 +36,20 @@
3636
import org.apache.commons.logging.Log;
3737
import org.apache.commons.logging.LogFactory;
3838
import org.dataloader.DataLoader;
39-
import org.springframework.context.expression.BeanFactoryResolver;
40-
import org.springframework.expression.BeanResolver;
4139
import reactor.core.publisher.Flux;
4240
import reactor.core.publisher.Mono;
4341

4442
import org.springframework.aop.support.AopUtils;
4543
import org.springframework.beans.factory.InitializingBean;
4644
import org.springframework.context.ApplicationContext;
4745
import org.springframework.context.ApplicationContextAware;
46+
import org.springframework.context.expression.BeanFactoryResolver;
4847
import org.springframework.core.KotlinDetector;
4948
import org.springframework.core.MethodIntrospector;
5049
import org.springframework.core.MethodParameter;
5150
import org.springframework.core.annotation.AnnotatedElementUtils;
5251
import org.springframework.core.convert.ConversionService;
52+
import org.springframework.expression.BeanResolver;
5353
import org.springframework.format.FormatterRegistrar;
5454
import org.springframework.format.support.DefaultFormattingConversionService;
5555
import org.springframework.format.support.FormattingConversionService;
@@ -156,7 +156,7 @@ public void afterPropertiesSet() {
156156
// Annotation based
157157
if (springDataPresent) {
158158
// Must be ahead of ArgumentMethodArgumentResolver
159-
this.argumentResolvers.addResolver(new ProjectedPayloadMethodArgumentResolver());
159+
this.argumentResolvers.addResolver(new ProjectedPayloadMethodArgumentResolver(obtainApplicationContext()));
160160
}
161161
this.argumentResolvers.addResolver(new ArgumentMapMethodArgumentResolver());
162162
GraphQlArgumentInitializer initializer = new GraphQlArgumentInitializer(this.conversionService);

spring-graphql/src/main/java/org/springframework/graphql/data/method/annotation/support/ProjectedPayloadMethodArgumentResolver.java

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,14 @@
1818

1919
import graphql.schema.DataFetchingEnvironment;
2020

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;
2522
import org.springframework.core.MethodParameter;
2623
import org.springframework.core.annotation.AnnotatedElementUtils;
2724
import org.springframework.data.projection.SpelAwareProxyProjectionFactory;
2825
import org.springframework.data.web.ProjectedPayload;
2926
import org.springframework.graphql.data.method.HandlerMethodArgumentResolver;
3027
import org.springframework.graphql.data.method.annotation.Argument;
28+
import org.springframework.util.Assert;
3129

3230
/**
3331
* Resolver to obtain an {@link ProjectedPayload @ProjectedPayload},
@@ -58,20 +56,22 @@
5856
* @author Mark Paluch
5957
* @since 1.0.0
6058
*/
61-
public class ProjectedPayloadMethodArgumentResolver implements HandlerMethodArgumentResolver,
62-
BeanFactoryAware, BeanClassLoaderAware {
59+
public class ProjectedPayloadMethodArgumentResolver implements HandlerMethodArgumentResolver {
6360

6461
private final SpelAwareProxyProjectionFactory projectionFactory = new SpelAwareProxyProjectionFactory();
6562

6663

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+
}
7575
}
7676

7777

0 commit comments

Comments
 (0)