spkrgg
80
2019-12-27 16:19:09 작성 2019-12-27 16:27:15 수정됨
2
540

Spring mybatis 관련 NullPointerExeption 질문입니다


안녕하세요 초보 코딩러입니다 ㅜㅜ


지금 제가 하고있는게 사용자가 제가 만든 해당 사이트에 들어갈 때마다 사용자의 ip, user-agent가 db에 insert 되는 것을 지금 코드로 짜고 있는데요, 자꾸 dao 부분에서 널포인트 익셉션이 뜹니다. 코드는 이렇습니다.

주소창에 치고 들어갈 때마다 실행되는 VisitCounter부분입니다. httpsessionlistener를 통해서 실행될 때 마다 코드가 실행되게 했습니다.







dao 부분입니다.


visitcountvo 부분입니다.



mybatis 부분입니다





에러코드입니다ㅠ

12월 27, 2019 4:08:23 오후 org.apache.catalina.session.StandardSession tellNew

SEVERE: 세션 이벤트 리스너가 예외를 발생시켰습니다.

java.lang.NullPointerException

at org.zerock.persistence.VisitCountDAOImpl.insertVisitor(VisitCountDAOImpl.java:23)

at org.zerock.visitcounter.VisitCounter.sessionCreated(VisitCounter.java:37)

at org.apache.catalina.session.StandardSession.tellNew(StandardSession.java:388)

at org.apache.catalina.session.StandardSession.setId(StandardSession.java:360)

at org.apache.catalina.session.StandardSession.setId(StandardSession.java:341)

at org.apache.catalina.session.ManagerBase.createSession(ManagerBase.java:686)

at org.apache.catalina.connector.Request.doGetSession(Request.java:3037)

at org.apache.catalina.connector.Request.getSession(Request.java:2432)

at org.apache.catalina.connector.RequestFacade.getSession(RequestFacade.java:908)

at javax.servlet.http.HttpServletRequestWrapper.getSession(HttpServletRequestWrapper.java:244)

at org.apache.catalina.core.ApplicationHttpRequest.getSession(ApplicationHttpRequest.java:582)

at org.apache.catalina.core.ApplicationHttpRequest.getSession(ApplicationHttpRequest.java:527)

at org.apache.jasper.runtime.PageContextImpl.initialize(PageContextImpl.java:133)

at org.apache.jasper.runtime.JspFactoryImpl.internalGetPageContext(JspFactoryImpl.java:109)

at org.apache.jasper.runtime.JspFactoryImpl.getPageContext(JspFactoryImpl.java:60)

at org.apache.jsp.WEB_002dINF.views.user.login_jsp._jspService(login_jsp.java:107)

at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:741)

at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:477)

at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:385)

at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:329)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:741)

at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)

at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)

at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)

at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)

at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)

at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:712)

at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:459)

at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:384)

at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:312)

at org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:168)

at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:303)

at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1244)

at org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1027)

at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:971)

at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893)

at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:967)

at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:858)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:634)

at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:843)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:741)

at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)

at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)

at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)

at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)

at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)

at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:85)

at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)

at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)

at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)

at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:202)

at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)

at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:526)

at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139)

at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)

at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:678)

at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74)

at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)

at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:367)

at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)

at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:860)

at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1591)

at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)

at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)

at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)

at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)

at java.base/java.lang.Thread.run(Thread.java:830)


여기서 어떤 부분에서 null이 되는건지 모르겠습니다... ㅠㅠ 도와주시면 감사드리겠습니다

0
  • 답변 2

  • gwk
    444
    2019-12-27 16:25:48

    SqlSession session 이게 잘 inject 됐나 확인해보세요. null이 아닌지

  • spkrgg
    80
    2019-12-27 17:08:45

    sqlsession은 잘 되는것 같습니다,,, 근데 제가 web.xml에서 리스너로 맨 위 사진에 있는 VisitCounter 클래스를 등록해놨는데요, 여기서 httpsessionlistener 인터페이스 안의 sessionCreated 메소드의 매개로 있는 이벤트 arg0을 세션에 할당하지 않아서 혹시 익셉션이 뜨는걸까여?

  • 로그인을 하시면 답변을 등록할 수 있습니다.