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
This commit is contained in:
@@ -36,8 +36,6 @@ import graphql.schema.idl.RuntimeWiring;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.dataloader.DataLoader;
|
||||
import org.springframework.context.expression.BeanFactoryResolver;
|
||||
import org.springframework.expression.BeanResolver;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
@@ -45,11 +43,13 @@ import org.springframework.aop.support.AopUtils;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ApplicationContextAware;
|
||||
import org.springframework.context.expression.BeanFactoryResolver;
|
||||
import org.springframework.core.KotlinDetector;
|
||||
import org.springframework.core.MethodIntrospector;
|
||||
import org.springframework.core.MethodParameter;
|
||||
import org.springframework.core.annotation.AnnotatedElementUtils;
|
||||
import org.springframework.core.convert.ConversionService;
|
||||
import org.springframework.expression.BeanResolver;
|
||||
import org.springframework.format.FormatterRegistrar;
|
||||
import org.springframework.format.support.DefaultFormattingConversionService;
|
||||
import org.springframework.format.support.FormattingConversionService;
|
||||
@@ -156,7 +156,7 @@ public class AnnotatedControllerConfigurer
|
||||
// Annotation based
|
||||
if (springDataPresent) {
|
||||
// Must be ahead of ArgumentMethodArgumentResolver
|
||||
this.argumentResolvers.addResolver(new ProjectedPayloadMethodArgumentResolver());
|
||||
this.argumentResolvers.addResolver(new ProjectedPayloadMethodArgumentResolver(obtainApplicationContext()));
|
||||
}
|
||||
this.argumentResolvers.addResolver(new ArgumentMapMethodArgumentResolver());
|
||||
GraphQlArgumentInitializer initializer = new GraphQlArgumentInitializer(this.conversionService);
|
||||
|
||||
@@ -18,16 +18,14 @@ package org.springframework.graphql.data.method.annotation.support;
|
||||
|
||||
import graphql.schema.DataFetchingEnvironment;
|
||||
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.factory.BeanClassLoaderAware;
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.beans.factory.BeanFactoryAware;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.core.MethodParameter;
|
||||
import org.springframework.core.annotation.AnnotatedElementUtils;
|
||||
import org.springframework.data.projection.SpelAwareProxyProjectionFactory;
|
||||
import org.springframework.data.web.ProjectedPayload;
|
||||
import org.springframework.graphql.data.method.HandlerMethodArgumentResolver;
|
||||
import org.springframework.graphql.data.method.annotation.Argument;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* Resolver to obtain an {@link ProjectedPayload @ProjectedPayload},
|
||||
@@ -58,20 +56,22 @@ import org.springframework.graphql.data.method.annotation.Argument;
|
||||
* @author Mark Paluch
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public class ProjectedPayloadMethodArgumentResolver implements HandlerMethodArgumentResolver,
|
||||
BeanFactoryAware, BeanClassLoaderAware {
|
||||
public class ProjectedPayloadMethodArgumentResolver implements HandlerMethodArgumentResolver {
|
||||
|
||||
private final SpelAwareProxyProjectionFactory projectionFactory = new SpelAwareProxyProjectionFactory();
|
||||
|
||||
|
||||
@Override
|
||||
public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
|
||||
this.projectionFactory.setBeanFactory(beanFactory);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBeanClassLoader(ClassLoader classLoader) {
|
||||
this.projectionFactory.setBeanClassLoader(classLoader);
|
||||
/**
|
||||
* Create a new {@link ProjectedPayloadMethodArgumentResolver} using the given context.
|
||||
* @param applicationContext the {@link ApplicationContext} to use for bean lookup and class loading
|
||||
*/
|
||||
public ProjectedPayloadMethodArgumentResolver(ApplicationContext applicationContext) {
|
||||
Assert.notNull(applicationContext, "ApplicationContext must not be null");
|
||||
this.projectionFactory.setBeanFactory(applicationContext);
|
||||
ClassLoader classLoader = applicationContext.getClassLoader();
|
||||
if(classLoader != null) {
|
||||
this.projectionFactory.setBeanClassLoader(classLoader);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user