找不到`MessagesApi`的限定bean

时间:2018-02-21 23:28:11

标签: playframework guice playframework-2.4

我已将messagesApi注入我的控制器documented(播放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: {}

1 个答案:

答案 0 :(得分:0)

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

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

有关详细信息,请查看Play documents