2016-03-14 75 views
2

我試圖從我的Play應用程序發送電子郵件。 電子郵件對象由另一個類準備,並傳遞給將發送電子郵件的控制器。嘗試發送電子郵件時,會引發致命異常。 我的控制器設置是這樣的:致命異常MailerClient播放2.5

public class UserController extends BaseController<User> { 

@Inject 
MailerClient mailerClient; 

@Inject 
public UserController(MailerClient client) { 
    super(new UserService()); 
    mailerClient = client; 
} 

public Result create(){ 
    resourceForm = formFactory.form(User.class); 
    Form<User> filledForm = resourceForm.bindFromRequest(); 
    if(filledForm.hasErrors()){ 
     return badRequest(filledForm.errorsAsJson()); 
    } 
    User user = filledForm.get(); 
    Map emailMap = new HashMap<>(); 
    emailMap.put("email" , user.email); 
    List<User> existingUser = service.where(emailMap); 
    if(existingUser.size() != 0){ 
     return JsonResponse.JsonMessage(BAD_REQUEST , "This Email is already registered"); 
    }else{ 
     user.status = getStatus(DORMANT); 
     user.save(); 
     UserRegistration registration = new UserRegistration(user); 
     registration.save(); 

     Email email = EmailDispatcher.buildEmail(ACTIVATION , user.email , registration.link); 
     mailerClient.send(email); 

    } 
    return ok(Json.toJson(user)); 
} 

我的電子郵件配置設置爲:

play.mailer{ 
    host = "smtp.gmail.com" 
    port = 465 
    ssl = yes 
    user = "[email protected]" 
    password = password 
} 

調用mailerClient.send(email)在我的控制器導致以下異常被拋出:

[error] a.a.ActorSystemImpl - Uncaught fatal error from thread [application-akka.actor.default-dispatcher-2] shutting down ActorSystem [application] 
java.lang.NoSuchMethodError: play.api.PlayConfig.getOptional(Ljava/lang/String;Lplay/api/ConfigLoader;)Lscala/Option; 
     at play.api.libs.mailer.CommonsMailer.instance$lzycompute(MailerPlugin.scala:92) 
     at play.api.libs.mailer.CommonsMailer.instance(MailerPlugin.scala:88) 
     at play.api.libs.mailer.CommonsMailer.send(MailerPlugin.scala:109) 
     at play.api.libs.mailer.MailerClient$class.send(MailerPlugin.scala:44) 
     at play.api.libs.mailer.CommonsMailer.send(MailerPlugin.scala:83) 
     at controllers.api.UserController.create(UserController.java:57) 
     at router.Routes$$anonfun$routes$1$$anonfun$applyOrElse$6$$anonfun$apply$6.apply(Routes.scala:242) 
     at router.Routes$$anonfun$routes$1$$anonfun$applyOrElse$6$$anonfun$apply$6.apply(Routes.scala:242) 
     at play.core.routing.HandlerInvokerFactory$$anon$4.resultCall(HandlerInvoker.scala:157) 
     at play.core.routing.HandlerInvokerFactory$$anon$4.resultCall(HandlerInvoker.scala:156) 

我使用梅勒版本3.0.1,我的build.sbt如下:

name := """API""" 

version := "1.0-SNAPSHOT" 

lazy val root = (project in file(".")).enablePlugins(PlayJava, PlayEbean) 

scalaVersion := "2.11.7" 

    libraryDependencies ++= Seq(
     javaJdbc, 
     cache, 
     javaWs, 
     "mysql" % "mysql-connector-java" % "5.1.16", 
     "de.svenkubiak" % "jBCrypt" % "0.4", 
     "com.typesafe.play" %% "play-mailer" % "3.0.1" 
    ) 

我一直無法找到一個類似的問題在其他地方

+0

什麼插件版本您使用的? – Franz

+0

我正在使用3.0.1,我更新了問題以顯示它。 –

+0

他們發佈了一個新版本。我使用'「com.typesafe.play」%「play-mailer_2.11」%「5.0.0-M1」'它可以工作。 – Franz

回答

3

您的版本更改爲5.0.0-M1

libraryDependencies ++= Seq(
    javaJdbc, 
    cache, 
    javaWs, 
    "mysql" % "mysql-connector-java" % "5.1.38", 
    "de.svenkubiak" % "jBCrypt" % "0.4", 
    "com.typesafe.play" %% "play-mailer" % "5.0.0-M1" 
) 

我只是解決了它這樣的幾分鐘,你喜歡遲到1版本4.0.0-M1和2.4.0的4.0.0版本的新版本,但2.5.0版本的5.0.0-M1,從今天起26天前更新的播放器。

編輯: 5.0.0版發佈了,你可以用它:

"com.typesafe.play" %% "play-mailer" % "5.0.0"