grails - 名为 'mailService'的bean应该是 'grails.plugins.mail.MailService'类型,但实际上是 'eafya.MailService'类型

标签 grails

我正在为我的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/

相关文章:

xml - Grails 3-具有XML的Marshaller

iphone - 如何为Grails应用创建移动界面?

grails - 将BIRT 3.7与Grails 2.5一起使用时返回NoSuchMethodError

grails - 如何自定义UsernamePasswordAuthenticationFilter

java - 如何在 grails 2.0.3 中对服务进行单元测试?

grails - 从远程机器访问正在运行的 Grails 应用程序

mysql - GRAILS:使用域子类

grails - 注册自定义约束

hibernate - 找不到表; SQL语句

html - 可以在 <g :actionSubmit> tag? 中添加 css