주라주라
30
2021-05-05 19:36:35
5
145

스프링 세팅 시 dao에서 null 에러가 뜹니다ㅠㅠ


이 오류 때문에 3일은 고민하고 있네요ㅠㅠ 

문제가 되는 부분이 SqlSession을 Autowired해주는 부분인데 

Autowired를 안하면 널, 하면 인젝션에러가 뜹니다.

어느부분에서 설정이 잘못된건지 답변주시면 감사하겠습니다ㅠㅠ


**오류 콘솔

5월 05, 2021 7:32:19 오후 org.apache.catalina.core.StandardWrapperValve invoke
심각: Servlet.service() for servlet [appServlet] in context with path [] threw exception [Request processing failed; nested exception is java.lang.NullPointerException] with root cause
java.lang.NullPointerException
	at kr.co.test.Dao.ProjectDao.selectProjectList(ProjectDao.java:25)
	at kr.co.test.Service.Impl.ProjectServiceImpl.selectProjectList(ProjectServiceImpl.java:27)
	at kr.co.test.Controller.ProjectController.projectList(ProjectController.java:41)
	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:498)
	at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:205)
	at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:133)
	at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:97)
	at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:854)
	at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:765)
	at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
	at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:967)
	at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:901)
	at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)
	at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:622)
	at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:292)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
	at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
	at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:528)
	at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1100)
	at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:687)
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1520)
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1476)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
	at java.lang.Thread.run(Thread.java:748)


**설정부분

   <!-- set Mybatis query xml -->
   <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
      <property name="dataSource" ref="dataSource" />
      <property name="configLocation" value="classpath:META-INF/mybatis/mybatis-config.xml" />     
      <property name="mapperLocations" value="classpath:/sql/**/*Mapper.xml" />
   </bean>
   <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
   	<property name="basePackage"><value>kr.co.test.**.dao</value></property>
   </bean>
</beans>


**오라클설정부분

<!-- 오라클 설정 - 아이피:포트번호:서비스-->
   <bean id="dataSourceProxy" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
      <property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"/>
      <property name="url" value="jdbc:oracle:thin:@localhost:1521:orcl" />
      <property name="username" value="scott" />
      <property name="password" value="tiger" />
   </bean>

   <bean id="sqlSession" class="org.mybatis.spring.SqlSessionTemplate">
      <constructor-arg ref="sqlSessionFactory" />
   </bean>



0
  • 답변 5

  • Dev.kerberos
    937
    2021-05-05 22:33:02


    at kr.co.test.Dao.ProjectDao.selectProjectList(ProjectDao.java:25)

    여기 25번째줄에서 났는데요??저기소스를한번..


  • 주라주라
    30
    2021-05-05 23:20:15

    @ Dev.kerberos 님 답변 감사합니다

    dao에서 25번째 줄은 제가 콘솔  확인하려고 sysout찍어놓은거예요...ㅠㅠ

    현재 dao는 이렇게 밖에 없습니다...


    **Dao

           @Autowired
    	private SqlSession sqlSession;	
    	private final String PREFIX = "projectMapper.";
    	
    	public List<ProjectVo> selectProjectList(ProjectVo ProjectVo) {
    		
    		return sqlSession.selectList(PREFIX + "selectProjectList", ProjectVo);
    	}
    	


    **sql


    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
    
    <mapper namespace="projectMapper">
    	 <select id="selectProjectList" parameterType="ProjectVo" resultType="ProjectVo">
    	 	SELECT CITY 
    		        ,CITY_ENG
    		        ,SIGUNGU 
    		        ,ADDR1 
    		        ,ADDR2 
    		        ,BRAND 
    		        ,STORE_NM 
    		        ,STORE_TELNO 
    		FROM MICHAA_STORE
    	 	</select>
    


  • Dev.kerberos
    937
    2021-05-06 14:31:47

    dao에서 ProjectVo ProjectVo 여기에서 ProjectVo 이값은있느거죠?

  • 주라주라
    30
    2021-05-06 23:16:49

    @Dev.kerberos


    넵.. 해줘야하는건 빠짐없이 다 들어갔다고 생각하는데

    계속 오류가 나니까 참 답답하네요..ㅠㅠㅠㅠ

  • 넘추운우리집
    44
    2021-05-11 18:13:24

    해결하셨는지 모르겠지만..

    비슷한  경험을 해본적이 있는데 어떻게 해결했었는지 기억이 가물가물하네요.

    xml로 등록이 안되면 java 코드로 직접 등록하거나 , sqlsession 구성할때 끌어오는 datasource 

    이런것들 제대로 주입되는지 한번 확인해봤던 기억이 납니다.


    그리고 분할되어있는 xml 의 순서였는지, bean 등록 순서였는지 기억은 안나는데  어떤 순서를 바꾸었던 기억도 있습니다.




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