Netflix / dgs-framework

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

bug: Cannot start-up spring boot app #1262

Closed robertionut95b closed 9 months ago

robertionut95b commented 2 years ago

Please read our contributor guide before creating an issue.

Hello,

I have just migrated my project on a separate branch from graphql-kickstarter to dgs. Unfortunately, I cannot boot-up the application after adding the required dependencies and modifying the data fetching logic to DGS's concepts.

Am I missing something from the configuration?

Expected behavior

Application should start as usual.

Actual behavior

19:19:18.950 [Thread-0] DEBUG org.springframework.boot.devtools.restart.classloader.RestartClassLoader - Created RestartClassLoader org.springframework.boot.devtools.restart.classloader.RestartClassLoader@67140c78

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::                (v2.7.4)

2022-10-06 19:19:19.705  INFO 9480 --- [  restartedMain] com.irb.paxton.PaxtonApplication         : Starting PaxtonApplication using Java 18.0.2.1 on DESKTOP-2LNU0MA with PID 9480 (D:\storage\projects\paxton\apps\paxton-api\target\classes started by rober in D:\storage\projects\paxton\apps\paxton-api)
2022-10-06 19:19:19.706  INFO 9480 --- [  restartedMain] com.irb.paxton.PaxtonApplication         : No active profile set, falling back to 1 default profile: "default"
2022-10-06 19:19:19.794  INFO 9480 --- [  restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : Devtools property defaults active! Set 'spring.devtools.add-properties' to 'false' to disable
2022-10-06 19:19:19.794  INFO 9480 --- [  restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : For additional web related logging consider setting the 'logging.level.web' property to 'DEBUG'
2022-10-06 19:19:22.104  INFO 9480 --- [  restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2022-10-06 19:19:22.431  INFO 9480 --- [  restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 313 ms. Found 12 JPA repository interfaces.
2022-10-06 19:19:24.177  INFO 9480 --- [  restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
2022-10-06 19:19:24.197  INFO 9480 --- [  restartedMain] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2022-10-06 19:19:24.198  INFO 9480 --- [  restartedMain] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.65]
2022-10-06 19:19:24.425  INFO 9480 --- [  restartedMain] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2022-10-06 19:19:24.426  INFO 9480 --- [  restartedMain] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 4631 ms
2022-10-06 19:19:24.906  INFO 9480 --- [  restartedMain] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Starting...
2022-10-06 19:19:25.278  INFO 9480 --- [  restartedMain] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Start completed.
2022-10-06 19:19:25.295  INFO 9480 --- [  restartedMain] o.s.b.a.h2.H2ConsoleAutoConfiguration    : H2 console available at '/h2-console'. Database available at 'jdbc:h2:file:./db/paxton-db'
2022-10-06 19:19:25.783  INFO 9480 --- [  restartedMain] o.hibernate.jpa.internal.util.LogHelper  : HHH000204: Processing PersistenceUnitInfo [name: default]
2022-10-06 19:19:25.864  INFO 9480 --- [  restartedMain] org.hibernate.Version                    : HHH000412: Hibernate ORM core version 5.6.11.Final
2022-10-06 19:19:26.124  INFO 9480 --- [  restartedMain] o.hibernate.annotations.common.Version   : HCANN000001: Hibernate Commons Annotations {5.1.2.Final}
2022-10-06 19:19:26.277  INFO 9480 --- [  restartedMain] org.hibernate.dialect.Dialect            : HHH000400: Using dialect: org.hibernate.dialect.H2Dialect
2022-10-06 19:19:28.158  INFO 9480 --- [  restartedMain] o.h.e.t.j.p.i.JtaPlatformInitiator       : HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
2022-10-06 19:19:28.171  INFO 9480 --- [  restartedMain] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2022-10-06 19:19:29.592 ERROR 9480 --- [  restartedMain] com.irb.paxton.mail.PaxtonMailService    : Smtp connection refused, please check application properties. This connection is required for user management activities
2022-10-06 19:19:30.430  INFO 9480 --- [  restartedMain] o.s.s.web.DefaultSecurityFilterChain     : Will secure any request with [org.springframework.security.web.session.DisableEncodeUrlFilter@69e7087e, org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter@14599c9b, org.springframework.security.web.context.SecurityContextPersistenceFilter@4d1d42a8, org.springframework.security.web.header.HeaderWriterFilter@706eb376, org.springframework.security.web.csrf.CsrfFilter@40a77ec7, org.springframework.security.web.authentication.logout.LogoutFilter@1997d3b8, com.irb.paxton.security.auth.jwt.JwtCookieAuthenticationFilter@4624d7e4, org.springframework.security.oauth2.server.resource.web.BearerTokenAuthenticationFilter@4357d293, org.springframework.security.web.authentication.www.BasicAuthenticationFilter@574dee2e, org.springframework.security.web.savedrequest.RequestCacheAwareFilter@671d0451, org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter@40321218, org.springframework.security.web.authentication.AnonymousAuthenticationFilter@4dd809f, com.irb.paxton.security.cors.CorsFilter@16482560, org.springframework.security.web.session.SessionManagementFilter@5b0298f1, org.springframework.security.web.access.ExceptionTranslationFilter@35c3f01b, org.springframework.security.web.access.intercept.FilterSecurityInterceptor@622a1053]
2022-10-06 19:19:30.880  WARN 9480 --- [  restartedMain] JpaBaseConfiguration$JpaWebConfiguration : spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view rendering. Explicitly configure spring.jpa.open-in-view to disable this warning
2022-10-06 19:19:32.052  INFO 9480 --- [  restartedMain] c.n.g.d.w.a.GraphiQLConfigurer           : Configuring GraphiQL to use GraphQL endpoint at '/graphql'
2022-10-06 19:19:32.441  WARN 9480 --- [  restartedMain] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'dgsQueryExecutor' defined in class path resource [com/netflix/graphql/dgs/autoconfig/DgsAutoConfiguration.class]: Unsatisfied dependency expressed through method 'dgsQueryExecutor' parameter 1; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'schema' defined in class path resource [com/netflix/graphql/dgs/autoconfig/DgsAutoConfiguration.class]: Unsatisfied dependency expressed through method 'schema' parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'dgsSchemaProvider' defined in class path resource [com/netflix/graphql/dgs/autoconfig/DgsAutoConfiguration.class]: Unsatisfied dependency expressed through method 'dgsSchemaProvider' parameter 9; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'methodDataFetcherFactory' defined in class path resource [com/netflix/graphql/dgs/autoconfig/DgsAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.netflix.graphql.dgs.internal.method.MethodDataFetcherFactory]: Factory method 'methodDataFetcherFactory' threw exception; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'requestHeaderMapResolver' defined in class path resource [com/netflix/graphql/dgs/webmvc/autoconfigure/DgsWebMvcAutoConfiguration$WebMvcArgumentHandlerConfiguration.class]: Unsatisfied dependency expressed through method 'requestHeaderMapResolver' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dgsWebDataBinderFactory' defined in class path resource [com/netflix/graphql/dgs/webmvc/autoconfigure/DgsWebMvcAutoConfiguration$WebMvcArgumentHandlerConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.web.bind.support.WebDataBinderFactory]: Factory method 'dgsWebDataBinderFactory' threw exception; nested exception is org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type 'org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter' available: expected single matching bean but found 2: requestMappingHandlerAdapter,repositoryExporterHandlerAdapter
2022-10-06 19:19:32.455  INFO 9480 --- [  restartedMain] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'default'
2022-10-06 19:19:32.455  INFO 9480 --- [  restartedMain] .SchemaDropperImpl$DelayedDropActionImpl : HHH000477: Starting delayed evictData of schema as part of SessionFactory shut-down'
2022-10-06 19:19:32.486  INFO 9480 --- [  restartedMain] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Shutdown initiated...
2022-10-06 19:19:32.520  INFO 9480 --- [  restartedMain] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Shutdown completed.
2022-10-06 19:19:32.525  INFO 9480 --- [  restartedMain] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]
2022-10-06 19:19:32.558  INFO 9480 --- [  restartedMain] ConditionEvaluationReportLoggingListener : 

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2022-10-06 19:19:32.589 ERROR 9480 --- [  restartedMain] o.s.b.d.LoggingFailureAnalysisReporter   : 

***************************
APPLICATION FAILED TO START
***************************

Description:

Parameter 0 of method requestHeaderMapResolver in com.netflix.graphql.dgs.webmvc.autoconfigure.DgsWebMvcAutoConfiguration$WebMvcArgumentHandlerConfiguration required a single bean, but 2 were found:
    - requestMappingHandlerAdapter: defined by method 'requestMappingHandlerAdapter' in class path resource [org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class]
    - repositoryExporterHandlerAdapter: defined by method 'repositoryExporterHandlerAdapter' in class path resource [org/springframework/data/rest/webmvc/config/RepositoryRestMvcConfiguration.class]

Action:

Consider marking one of the beans as @Primary, updating the consumer to accept multiple beans, or using @Qualifier to identify the bean that should be consumed

Process finished with exit code 0

Steps to reproduce

The branch repo is available at https://github.com/robertionut95b/paxton/tree/dgs-graphql/apps/paxton-api

Note: A test case would be highly appreciated, but we understand that's not always possible

gho1b commented 1 year ago

I got same issue, this issue occured when using org.springframework.boot:spring-boot-starter-data-rest in the depedencies that make method com.netflix.graphql.dgs.webmvc.autoconfigure.DgsWebMvcAutoConfiguration.WebMvcArgumentHandlerConfiguration#dgsWebDataBinderFactory have 2 bean candidates

we have 2 possible solution for this issue:

  1. Downgrande the dgs to 4.9.10 because this version have no DgsWebMvcAutoConfiguration.DgsWebMvcAutoConfiguration.WebMvcArgumentHandlerConfiguration class

  2. override the WebMvcArgumentHandlerConfiguration class with other configuration then force pick qualified bean for DgsWebMvcAutoConfiguration.WebMvcArgumentHandlerConfiguration#dgsWebDataBinderFactory parameter just like this

@Configuration
@Import(value = [DgsWebMvcAutoConfiguration.WebMvcArgumentHandlerConfiguration::class])
class DgsConfiguration {
    @Qualifier
    private annotation class Dgs

    @Bean
    @Dgs
    fun dgsWebDataBinderFactory(@Qualifier("requestMappingHandlerAdapter") adapter: ObjectProvider<RequestMappingHandlerAdapter>): WebDataBinderFactory {
        return ServletRequestDataBinderFactory(listOf(), adapter.ifAvailable?.webBindingInitializer)
    }

    @Bean
    open fun requestHeaderMapResolver(@Dgs dataBinderFactory: WebDataBinderFactory): ArgumentResolver {
        return HandlerMethodArgumentResolverAdapter(RequestHeaderMapMethodArgumentResolver(), dataBinderFactory)
    }

    @Bean
    open fun requestHeaderResolver(beanFactory: ConfigurableBeanFactory, @Dgs dataBinderFactory: WebDataBinderFactory): ArgumentResolver {
        return HandlerMethodArgumentResolverAdapter(
            RequestHeaderMethodArgumentResolver(beanFactory),
            dataBinderFactory
        )
    }

    @Bean
    open fun requestParamResolver(@Dgs dataBinderFactory: WebDataBinderFactory): ArgumentResolver {
        return HandlerMethodArgumentResolverAdapter(RequestParamMethodArgumentResolver(false), dataBinderFactory)
    }

    @Bean
    open fun requestParamMapResolver(@Dgs dataBinderFactory: WebDataBinderFactory): ArgumentResolver {
        return HandlerMethodArgumentResolverAdapter(RequestParamMapMethodArgumentResolver(), dataBinderFactory)
    }

    @Bean
    open fun cookieValueResolver(beanFactory: ConfigurableBeanFactory, @Dgs dataBinderFactory: WebDataBinderFactory): ArgumentResolver {
        return HandlerMethodArgumentResolverAdapter(ServletCookieValueMethodArgumentResolver(beanFactory), dataBinderFactory)
    }
}
srinivasankavitha commented 1 year ago

Thanks for reporting. I think we can fix this by adding the qualifier in the framework so it doesn't clash.

On Mon, Jan 30, 2023 at 8:03 AM gho1b @.***> wrote:

I got same issue, this issue occured when using org.springframework.boot:spring-boot-starter-data-rest in the depedencies that make method com.netflix.graphql.dgs.webmvc.autoconfigure.DgsWebMvcAutoConfiguration.WebMvcArgumentHandlerConfiguration#dgsWebDataBinderFactory have 2 bean candidates

we have 2 possible solution for this issue:

1.

Downgrande the dgs to 4.9.10 because this version have no com.netflix.graphql.dgs.webmvc.autoconfigure.DgsWebMvcAutoConfiguration.WebMvcArgumentHandlerConfiguration class 2.

override the com.netflix.graphql.dgs.webmvc.autoconfigure.DgsWebMvcAutoConfiguration.WebMvcArgumentHandlerConfiguration class with other configuration. just like this

@Configuration @Import(value = [DgsWebMvcAutoConfiguration.WebMvcArgumentHandlerConfiguration::class]) class DgsConfiguration { @Qualifier private annotation class Dgs

@Bean
@Dgs
fun ***@***.***("requestMappingHandlerAdapter") adapter: ObjectProvider<RequestMappingHandlerAdapter>): WebDataBinderFactory {
    return ServletRequestDataBinderFactory(listOf(), adapter.ifAvailable?.webBindingInitializer)
}

@Bean
open fun ***@***.*** dataBinderFactory: WebDataBinderFactory): ArgumentResolver {
    return HandlerMethodArgumentResolverAdapter(RequestHeaderMapMethodArgumentResolver(), dataBinderFactory)
}

@Bean
open fun requestHeaderResolver(beanFactory: ConfigurableBeanFactory, @Dgs dataBinderFactory: WebDataBinderFactory): ArgumentResolver {
    return HandlerMethodArgumentResolverAdapter(
        RequestHeaderMethodArgumentResolver(beanFactory),
        dataBinderFactory
    )
}

@Bean
open fun ***@***.*** dataBinderFactory: WebDataBinderFactory): ArgumentResolver {
    return HandlerMethodArgumentResolverAdapter(RequestParamMethodArgumentResolver(false), dataBinderFactory)
}

@Bean
open fun ***@***.*** dataBinderFactory: WebDataBinderFactory): ArgumentResolver {
    return HandlerMethodArgumentResolverAdapter(RequestParamMapMethodArgumentResolver(), dataBinderFactory)
}

@Bean
open fun cookieValueResolver(beanFactory: ConfigurableBeanFactory, @Dgs dataBinderFactory: WebDataBinderFactory): ArgumentResolver {
    return HandlerMethodArgumentResolverAdapter(ServletCookieValueMethodArgumentResolver(beanFactory), dataBinderFactory)
}

}

— Reply to this email directly, view it on GitHub https://github.com/Netflix/dgs-framework/issues/1262#issuecomment-1408882845, or unsubscribe https://github.com/notifications/unsubscribe-auth/AJ5JPXNCHNVUKGF4FKMVGGDWU7Q4JANCNFSM6AAAAAAQ6ZXN2U . You are receiving this because you are subscribed to this thread.Message ID: @.***>

rahul-nehul commented 1 year ago

is there any working solution for this. cannot able to identify and understand solution posted by @gho1b

srinivasankavitha commented 1 year ago

We don't yet due to other priorities. If this is a blocker, please feel free to open a PR with a fix to unblock and we'd be happy to review and release.

kilink commented 9 months ago

Resolving since this issue was fixed in 58b5462 and 564e82d.