我正在为我的Web应用程序配置电子邮件,并且遇到此错误`
Bean named 'mailService' is expected to be of type 'grails.plugins.mail.MailService' but was actually of type 'eafya.MailService'
我在自己的build.gradle中添加了
compile 'org.grails.plugins:mail:2.0.0'
,但没有成功。我的EmailService代码:
package eafya
import grails.plugin.asyncmail.AsynchronousMailService
import grails.plugin.mail.MailService
class EmailService {
MailService mailService
def groovyPageRenderer
def grailsApplication
/**
* Sends the email to given email id
*/
def sendMail(MailDTO mailDTO) {
log.info "Sending Mail To ==== ${mailDTO?.toMailId}"
mailService.sendMail {
async true
to mailDTO?.toMailId
subject mailDTO.subject
html mailDTO.content
}
}
/*
* Sends the reset password email
*/
def sendResetPasswordEmail(Patient user, Token token) {
MailDTO mailDTO = new MailDTO()
mailDTO.with {
toMailId = user?.email
subject = "Password reset on Mobile Career Index"
content = groovyPageRenderer.render(template: '/mail/resetPassword', model: [user: user,token:token])
}
sendMail(mailDTO)
}
}
最佳答案
导入中MailService
的完整类名是grails.plugin.mail.MailService
,但是如错误消息所示,正确的类是grails.plugins.mail.MailService
。 Groovy会忽略无效的导入,因此就好像根本没有import语句一样,编译器希望它与EmailService
在同一包中。将导入更改为:
import grails.plugins.mail.MailService
关于grails - 名为 'mailService'的bean应该是 'grails.plugins.mail.MailService'类型,但实际上是 'eafya.MailService'类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48945813/