手上项目使用JFinal开发,配合使用JBolt工具,开发效率很高,因需要使用邮箱验证,找到了jfinal-mail-plugin(官方:https://gitee.com/xiyoufang/jfinal-mail-plugin),根据官方的说明文档,配置一遍后,注册了阿里的邮箱@aliyun.com做为测试邮箱,mail.properties文件配置如下:
#邮箱HOST host=smtp.aliyun.com #协议 protocol=smtp #端口 port=465 #发送邮箱 username=xxx@aliyun.com #密码 password=xxx #权限认证 mail.smtp.auth=true #超时时间 mail.smtp.timeout=5000 #是否是ssl mail.smtp.ssl.enable=true
但是项目启动,发现报错:
java.lang.ClassCastException: com.jfplugin.mail.MailPlugin cannot be cast to com.jfinal.plugin.IPlugin at com.jfinal.core.Config.startPlugins(Config.java:118) at com.jfinal.core.Config.configPluginWithOrder(Config.java:71) at com.jfinal.core.Config.configJFinal(Config.java:56) at com.jfinal.core.JFinal.init(JFinal.java:61) at com.jfinal.core.JFinalFilter.init(JFinalFilter.java:63) at io.undertow.servlet.core.LifecyleInterceptorInvocation.proceed(LifecyleInterceptorInvocation.java:111) at io.undertow.servlet.core.ManagedFilter.createFilter(ManagedFilter.java:80) at io.undertow.servlet.core.DeploymentManagerImpl$2.call(DeploymentManagerImpl.java:589) at io.undertow.servlet.core.DeploymentManagerImpl$2.call(DeploymentManagerImpl.java:554) at io.undertow.servlet.core.ServletRequestContextThreadSetupAction$1.call(ServletRequestContextThreadSetupAction.java:42) at io.undertow.servlet.core.ContextClassLoaderSetupAction$1.call(ContextClassLoaderSetupAction.java:43) at io.undertow.servlet.core.DeploymentManagerImpl.start(DeploymentManagerImpl.java:596) at com.jfinal.server.undertow.UndertowServer.configHttp(UndertowServer.java:277) at com.jfinal.server.undertow.UndertowServer.doStart(UndertowServer.java:255) at com.jfinal.server.undertow.UndertowServer.start(UndertowServer.java:152) at io.abcbtc.common.config.MainConfig.main(MainConfig.java:275)
解决办法:
1、找到undertow.properties文件,添加
undertow.hotSwapClassPrefix=com.jfplugin.mail.
2、调用
try{ MailKit.send(email,null, "标题", "内容....."); renderJson("data", "发送成功:"); }catch (Exception e){ renderJson("data", "发送失败"); e.printStackTrace(); }
undertow.hotSwapClassPrefix=com.jfplugin.
文档中早有说明:
https://www.jfinal.com/doc/1-5