【发布时间】:2021-06-27 17:35:16
【问题描述】:
我在 Grails 3.3.11 中遇到了一点问题,我需要帮助。
我正在 grails 3.3.11 中开发一个 rest-api,但我不能在服务中使用 i18n 的消息源。它只适用于我的控制器。
message = messageSource.getMessage('documentProperties.notFound', [partId,jsonRequestDoc.get("typeId")] as Object[], LocaleContextHolder.locale)
当我在上面执行此操作时,我会在服务中收到它。
Cannot invoke method getMessage() on null object
我的 messageSource 在我的服务类的开头定义如下:
@Autowired
def messageSource
为了解决这个问题,我手动创建了一个从控制器接收消息源的服务构造函数。
class CmbIdService {
public CmbIdService(def messageSource){
this.messageSource = messageSource
}
}
It was working as expected, but when I started running my integration tests, I noticed that Grails did not know how to instantiate my service considering the presence of the constructor. This the message I receive when I run the Grails Integration tests.
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'cmbIdService': Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type 'java.lang.Object' available: more than one 'primary' bean found among candidates... continue.
谁能帮帮我。我不知道该怎么办。我需要使用消息源进行国际化。我需要在服务中做到这一点,而不仅仅是在控制器中。我的测试需要继续进行。
谢谢!
阿尔弗雷多
【问题讨论】: