Ninja Framework mailProvider.get() 给出空指针异常

Ninja Framework mailProvider.get() gives a Null pointer exception

我都按照指示做了。

application.conf 包含:

smtp.host=smtp.gmail.com
smtp.port=465
smtp.ssl=true
smtp.user=myemail@gmail.com
smtp.password=xxxxxx
smtp.debug=false

代码包含

    package controllers;


import ninja.postoffice.Mail;
import ninja.postoffice.Postoffice;
import com.google.inject.Inject;
import com.google.inject.Provider;

public class MailController {

    @Inject
    Provider<Mail> mailProvider;

    @Inject
    Postoffice postoffice;

    public void sendMail(String to) {
        try {
        Mail mail = mailProvider.get();
......

它在 mailProvider.get() 处失败,给出 java.lang.NullPointerException

我错过了什么??

编辑,堆栈跟踪:

java.lang.NullPointerException
        at controllers.MailController.sendMail(MailController.java:19)
        at controllers.RegisterResendController.confirmation(RegisterResendController.java:37)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:497)
        at ninja.params.ControllerMethodInvoker.invoke(ControllerMethodInvoker.java:57)
        at ninja.FilterChainEnd.next(FilterChainEnd.java:49)
        at ninja.NinjaDefault.onRouteRequest(NinjaDefault.java:102)
        at ninja.servlet.NinjaServletDispatcher.service(NinjaServletDispatcher.java:86)
        at com.google.inject.servlet.ServletDefinition.doServiceImpl(ServletDefinition.java:287)
        at com.google.inject.servlet.ServletDefinition.doService(ServletDefinition.java:277)
        at com.google.inject.servlet.ServletDefinition.service(ServletDefinition.java:182)
        at com.google.inject.servlet.ManagedServletPipeline.service(ManagedServletPipeline.java:91)
        at com.google.inject.servlet.FilterChainInvocation.doFilter(FilterChainInvocation.java:85)
        at com.google.inject.servlet.ManagedFilterPipeline.dispatch(ManagedFilterPipeline.java:119)
        at com.google.inject.servlet.GuiceFilter.call(GuiceFilter.java:133)
        at com.google.inject.servlet.GuiceFilter.call(GuiceFilter.java:130)
        at com.google.inject.servlet.GuiceFilter$Context.call(GuiceFilter.java:203)
        at com.google.inject.servlet.GuiceFilter.doFilter(GuiceFilter.java:130)
        at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1652)
        at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:585)
        at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1127)
        at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:515)
        at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1061)
        at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
        at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97)
        at org.eclipse.jetty.server.Server.handle(Server.java:497)
        at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:310)
        at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:257)
        at org.eclipse.jetty.io.AbstractConnection.run(AbstractConnection.java:540)
        at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:635)
        at org.eclipse.jetty.util.thread.QueuedThreadPool.run(QueuedThreadPool.java:555)
        at java.lang.Thread.run(Thread.java:745)

您的 RegisterResendController 必须以某种方式获得 MailController 的实例。我怀疑 MailController 的实例没有注入到 RegisterSendController 中。因此缺少 Guice 提供的任何实例。确保您没有自己创建 class 的实例(通过 'new MailController' 等)。

如果您想获得更多反馈,请同时粘贴行号和 RegisterSendController。