ソースコードは
public class MailSenzer {
@Autowired
private JavaMailSender mailSender;
public void setMailSender(JavaMailSender mailSender) { this.mailSender = mailSender; }
public static void send(MailForm mail) {
new MailSenzer().senz(mail);
}
private void senz(MailForm mail) {
MimeMessage msger = mailSender.createMimeMessage();
try {
MimeMessageHelper msg = new MimeMessageHelper(msger, mail.getEncoding());
msg.setSubject(mail.getSubject());
msg.setText(mail.getContent(), true);
msg.setFrom(new InternetAddress(mail.getFrom()));
msg.setTo(new InternetAddress(mail.getTo(), mail.getTo_name(), mail.getEncoding()));
if(mail.getAttachment() != null) {
msg.addAttachment(MimeUtility.encodeText(mail.getAttachment_name(), "euc-kr", "B"), mail.getAttachment());
}
} catch(Exception ex) { System.out.println(ex); }
try {
mailSender.send(msger);
} catch(Exception ex) { System.out.println(ex); }
}
}
これは私が書いたコードです。コントローラーで同じコードを正確にテストしたところ、機能しましたが、静的メソッドとして実行しようとするとエラーが発生しました。
java.lang.NullPointerException
at kr.co.ubplay.utility.mail.MailSenzer.senz(MailSenzer.java:25)
at kr.co.ubplay.utility.mail.MailSenzer.send(MailSenzer.java:21)
at kr.co.ubplay.service.b2biz.controller.CoopEmailController.coop_send(CoopEmailController.java:116)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:213)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:126)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:96)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:617)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:578)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:923)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:789)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:936)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1004)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:1822)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662)
そして、npe を持つ行は
MimeMessage msger = mailSender.createMimeMessage();
スキャン用に com.ubis という名前の共通パッケージがあり、すべてのパッケージがそのドメインの下にあります。
これは、jsp 2.0 のカスタム タグ ライブラリで発生しています。動作中の dao にアクセスしようとしましたが、自動配線された sqlSession で npe が返されました。これらの問題の何が問題なのかわかりません:(