How to properly create an instance of AnnotatedControllerConfigurer

256 Views Asked by At

I'm trying to define a configuration to create an ExecutionGraphQlService to wire into an existing application as a proof of concept, but I'm a bit confused about how to create an instance of a AnnotatedControllerConfigurer. Here is what I currently have settled upon.

AnnotatedControllerConfigurer annotatedControllerConfigurer = new AnnotatedControllerConfigurer();

annotatedControllerConfigurer.setApplicationContext(applicationContext);
annotatedControllerConfigurer.afterPropertiesSet();
annotatedControllerConfigurer.configure(runtimeWiringBuilder);

AnnotatedControllerConfigurer implements ApplicationContextAware, InitializingBean so it seems to expect to be initialized as a bean, but attempts to autowire an instance of it fail due to Could not autowire. No beans of 'AnnotatedControllerConfigurer' type found. I've attempted constructor injection public ExecutionGraphQlService defaultExecutionGraphQlService(AnnotatedControllerConfigurer annotatedControllerConfigurer) as well as manual instantiation autowireCapableBeanFactory.autowireBean(annotatedControllerConfigurer) (which should be basically the same thing).

It seems like this class is not a bean, but expects to be managed by Spring's bean lifecycle? Is my approach the expected approach?

1

There are 1 best solutions below

0
On BEST ANSWER

The AnnotatedControllerConfigurer type is meant to be a bean in the Spring container, and is using the bean lifecycle to setup the infrastructure.

Creating it as a bean (given other pieces are contributed as beans as well). The runtime wiring should be configured on the GraphQlSource directly.

@Configuration(proxyBeanMethods = false)
class GraphQlConfiguration {

  @Bean
  public AnnotatedControllerConfigurer annotatedControllerConfigurer() {
    return new AnnotatedControllerConfigurer();
  }

}