【问题标题】:No qualifying bean found for `MessagesApi`没有为 `MessagesApi` 找到符合条件的 bean
【发布时间】:2018-02-21 23:28:10
【问题描述】:

我已将messagesApi 作为documented (Play 2.4.x) 注入到我的控制器中:

@Scope(value = "singleton")
@Component
class MyController @Inject()(val messagesApi: MessagesApi) extends Controller with I18nSupport

但在启动时:

Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [play.api.i18n.MessagesApi] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}

【问题讨论】:

    标签: playframework guice playframework-2.4


    【解决方案1】:

    您需要使用BaseControllerInjectedController 扩展您的控制器;所以你的代码将是:

    class MyController @Inject()(val messagesApi: MessagesApi) extends InjectedController with I18nSupport{}
    

    欲了解更多详情,您可以查看 Play 的documents

    【讨论】:

    • 感谢@Dave,但我仍在使用 2.4.x 呃,抱歉我没有在上面说!
    猜你喜欢
    • 2017-01-16
    • 2013-12-18
    • 1970-01-01
    • 1970-01-01
    • 2015-04-17
    • 2013-06-28
    • 1970-01-01
    • 2019-08-06
    相关资源
    最近更新 更多