Bean命名为' mailService'预计将类型为#grails.plugins.mail.MailService'但实际上是'eafya.MailService'

时间:2018-02-23 10:34:27

标签: grails

我正在处理我的网络应用程序的电子邮件配置,并收到此错误“

  

Bean命名为' mailService'预计将类型为#grails.plugins.mail.MailService'但实际上是#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)
    }
}

1 个答案:

答案 0 :(得分:0)

MailService导入中的完整班级名称为grails.plugin.mail.MailService,但正如错误消息所示,正确的班级为grails.plugins.mail.MailService。 Groovy忽略了无效的导入,因此就好像根本没有import语句,编译器希望它与EmailService在同一个包中。将导入更改为:

import grails.plugins.mail.MailService