Netflix / dgs-framework

GraphQL for Java with Spring Boot made easy.
https://netflix.github.io/dgs
Apache License 2.0
3.03k stars 286 forks source link

bug: DgsSpringGraphQLAutoConfiguration not compatible with WebFluxHateoasConfiguration #1946

Closed mformanek-ata closed 6 days ago

mformanek-ata commented 1 week ago

Hi, we have an application that has spring hateoas as a dependency and are in process of migration from old starter DGS starter to new one. Their configuration inside org.springframework.hateoas.config.WebFluxHateoasConfiguration contains following bean

@Bean
@Lazy
ServerWebExchangeContextFilter serverWebExchangeContextFilter() {
    return new ServerWebExchangeContextFilter();
}

which is also defined by DGS: https://github.com/Netflix/dgs-framework/blob/fb5e2f7404131feee7e9e16f9135e0fa5e68ec23/graphql-dgs-spring-graphql/src/main/kotlin/com/netflix/graphql/dgs/springgraphql/autoconfig/DgsSpringGraphQLAutoConfiguration.kt#L243

Expected behavior

App starts as expected

Actual behavior

App crashes on BeanDefinitionOverrideException

Caused by: org.springframework.beans.factory.support.BeanDefinitionOverrideException: Invalid bean definition with name 'serverWebExchangeContextFilter' defined in class path resource [org/springframework/hateoas/config/WebFluxHateoasConfiguration.class]: Cannot register bean definition [Root bean: class [null]; scope=; abstract=false; lazyInit=true; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.springframework.hateoas.config.WebFluxHateoasConfiguration; factoryMethodName=serverWebExchangeContextFilter; initMethodNames=null; destroyMethodNames=[(inferred)]; defined in class path resource [org/springframework/hateoas/config/WebFluxHateoasConfiguration.class]] for bean 'serverWebExchangeContextFilter' since there is already [Root bean: class [null]; scope=; abstract=false; lazyInit=null; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=com.netflix.graphql.dgs.springgraphql.autoconfig.DgsSpringGraphQLAutoConfiguration$ReactiveConfiguration; factoryMethodName=serverWebExchangeContextFilter; initMethodNames=null; destroyMethodNames=[(inferred)]; defined in class path resource [com/netflix/graphql/dgs/springgraphql/autoconfig/DgsSpringGraphQLAutoConfiguration$ReactiveConfiguration.class]]

Could you please add some condition, so that filter gets created only in case it does not already exist? :bowing_man:

srinivasankavitha commented 6 days ago

Thanks for pointing this out. fixed in #1949.