【问题标题】:Spring GraphQL projection throws no bean resolver exceptionSpring GraphQL 投影不引发 bean 解析器异常
【发布时间】:2022-10-25 19:01:47
【问题描述】:

我有一个带有 Spring for GraphQL 库的 Spring Boot 应用程序,我需要修改返回的对象。所以我创建并注册了一个引用我的 bean 方法的投影类:

public interface MyEntityProjection {

    @Value("#{@myBean.getName()}")
    public String getName();
}

但这会在运行查询时产生org.springframework.expression.spel.SpelEvaluationException: EL1057E: No bean resolver registered in the context to resolve access to bean 'myBean'。可能需要以某种方式注册 bean 解析器,但文档中没有信息 https://docs.spring.io/spring-graphql/docs/1.0.0-SNAPSHOT/reference/html/

说明我的问题的简单应用程序:https://github.com/omichal/spring-graphq-no-bean-resolver

【问题讨论】:

    标签: spring-graphql


    【解决方案1】:

    不幸的是,这是框架本身的一种非常固执己见的行为。
    你必须在你的法术前面加上目标. 在您的情况下,它将是:

    @Value("#{target.name}")
    

    默认情况下,框架会调用原始 bean 的 getName 方法——你不需要把 get.

    【讨论】:

      猜你喜欢
      • 2023-03-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-05-31
      • 2019-02-09
      • 1970-01-01
      • 1970-01-01
      • 2013-08-03
      相关资源
      最近更新 更多