[Exception ์ •๋ฆฌ] org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)

2022. 3. 10. 20:56ใ†๊ฐœ๋… ์ •๋ฆฌ ์ž‘์—…์‹ค/๋ฌธ์ œ ์ •๋ฆฌ

728x90
๋ฐ˜์‘ํ˜•

 

 

โš ๏ธ ๋ฌธ์ œ ๋ฐœ์ƒ!

 

2022-03-10 20:27:27.536 ERROR 2422 --- [nio-8080-exec-2] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.devcommunity.junyharang.mapper.support.DevInquryMapper.devInquryList] with root cause

org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.devcommunity.junyharang.mapper.support.DevInquryMapper.devInquryList
	at org.apache.ibatis.binding.MapperMethod$SqlCommand.<init>(MapperMethod.java:235) ~[mybatis-3.5.6.jar:3.5.6]
	at org.apache.ibatis.binding.MapperMethod.<init>(MapperMethod.java:53) ~[mybatis-3.5.6.jar:3.5.6]
	at org.apache.ibatis.binding.MapperProxy.lambda$cachedInvoker$0(MapperProxy.java:115) ~[mybatis-3.5.6.jar:3.5.6]
	at java.base/java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1705) ~[na:na]
	at org.apache.ibatis.binding.MapperProxy.cachedInvoker(MapperProxy.java:102) ~[mybatis-3.5.6.jar:3.5.6]
	at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:85) ~[mybatis-3.5.6.jar:3.5.6]
	at com.sun.proxy.$Proxy81.devInquryList(Unknown Source) ~[na:na]
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:na]
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
	at java.base/java.lang.reflect.Method.invoke(Method.java:566) ~[na:na]
	at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:344) ~[spring-aop-5.3.16.jar:5.3.16]
	at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:198) ~[spring-aop-5.3.16.jar:5.3.16]
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163) ~[spring-aop-5.3.16.jar:5.3.16]
	at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:137) ~[spring-tx-5.3.16.jar:5.3.16]
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.3.16.jar:5.3.16]
	at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:215) ~[spring-aop-5.3.16.jar:5.3.16]
	at com.sun.proxy.$Proxy82.devInquryList(Unknown Source) ~[na:na]
	at com.devcommunity.junyharang.service.support.DevInquryServiceImpl.devInquryList(DevInquryServiceImpl.java:39) ~[classes/:na]
	at com.devcommunity.junyharang.service.support.DevInquryServiceImpl$$FastClassBySpringCGLIB$$146fea12.invoke(<generated>) ~[classes/:na]
	at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218) ~[spring-core-5.3.16.jar:5.3.16]
	at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:783) ~[spring-aop-5.3.16.jar:5.3.16]
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163) ~[spring-aop-5.3.16.jar:5.3.16]
	at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:753) ~[spring-aop-5.3.16.jar:5.3.16]
	at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:123) ~[spring-tx-5.3.16.jar:5.3.16]
	at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:388) ~[spring-tx-5.3.16.jar:5.3.16]
	at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:119) ~[spring-tx-5.3.16.jar:5.3.16]
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.3.16.jar:5.3.16]
	at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:753) ~[spring-aop-5.3.16.jar:5.3.16]
	at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:698) ~[spring-aop-5.3.16.jar:5.3.16]
	at com.devcommunity.junyharang.service.support.DevInquryServiceImpl$$EnhancerBySpringCGLIB$$ebd8eac5.devInquryList(<generated>) ~[classes/:na]
	at com.devcommunity.junyharang.controller.support.DevInquryController.devInquryList(DevInquryController.java:75) ~[classes/:na]
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:na]
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
	at java.base/java.lang.reflect.Method.invoke(Method.java:566) ~[na:na]
	at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:205) ~[spring-web-5.3.16.jar:5.3.16]
	at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:150) ~[spring-web-5.3.16.jar:5.3.16]
	at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:117) ~[spring-webmvc-5.3.16.jar:5.3.16]
	at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:895) ~[spring-webmvc-5.3.16.jar:5.3.16]
	at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:808) ~[spring-webmvc-5.3.16.jar:5.3.16]
	at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87) ~[spring-webmvc-5.3.16.jar:5.3.16]
	at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1067) ~[spring-webmvc-5.3.16.jar:5.3.16]
	at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:963) ~[spring-webmvc-5.3.16.jar:5.3.16]
	at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006) ~[spring-webmvc-5.3.16.jar:5.3.16]
	at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:909) ~[spring-webmvc-5.3.16.jar:5.3.16]
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:681) ~[tomcat-embed-core-9.0.58.jar:4.0.FR]
	at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883) ~[spring-webmvc-5.3.16.jar:5.3.16]
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:764) ~[tomcat-embed-core-9.0.58.jar:4.0.FR]
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:227) ~[tomcat-embed-core-9.0.58.jar:9.0.58]
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) ~[tomcat-embed-core-9.0.58.jar:9.0.58]
	at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53) ~[tomcat-embed-websocket-9.0.58.jar:9.0.58]
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189) ~[tomcat-embed-core-9.0.58.jar:9.0.58]
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) ~[tomcat-embed-core-9.0.58.jar:9.0.58]
	at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201) ~[spring-web-5.3.16.jar:5.3.16]
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:117) ~[spring-web-5.3.16.jar:5.3.16]
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189) ~[tomcat-embed-core-9.0.58.jar:9.0.58]
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) ~[tomcat-embed-core-9.0.58.jar:9.0.58]
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:197) ~[tomcat-embed-core-9.0.58.jar:9.0.58]
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:97) ~[tomcat-embed-core-9.0.58.jar:9.0.58]
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:540) ~[tomcat-embed-core-9.0.58.jar:9.0.58]
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:135) ~[tomcat-embed-core-9.0.58.jar:9.0.58]
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92) ~[tomcat-embed-core-9.0.58.jar:9.0.58]
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:78) ~[tomcat-embed-core-9.0.58.jar:9.0.58]
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:359) ~[tomcat-embed-core-9.0.58.jar:9.0.58]
	at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:399) ~[tomcat-embed-core-9.0.58.jar:9.0.58]
	at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65) ~[tomcat-embed-core-9.0.58.jar:9.0.58]
	at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:889) ~[tomcat-embed-core-9.0.58.jar:9.0.58]
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1735) ~[tomcat-embed-core-9.0.58.jar:9.0.58]
	at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) ~[tomcat-embed-core-9.0.58.jar:9.0.58]
	at org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1191) ~[tomcat-embed-core-9.0.58.jar:9.0.58]
	at org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659) ~[tomcat-embed-core-9.0.58.jar:9.0.58]
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) ~[tomcat-embed-core-9.0.58.jar:9.0.58]
	at java.base/java.lang.Thread.run(Thread.java:829) ~[na:na]

 

MyBatis๋ฅผ ๊ณต๋ถ€ ํ•ด๋ณด๊ณ , ์ฒ˜์Œ ์‚ฌ์šฉ ํ•ด ๋ณด๋Š”๋ฐ, ์•Œ ์ˆ˜ ์—†๋Š” Exception์— ๋‹นํ™ฉ์„ ํ•œ ๊ฒƒ์ด์—์š”.

 

 

 

 

๐Ÿค” ์›์ธ ๋ถ„์„

ํ•ด๋‹น Exception์€ MyBatis๋ฅผ ์‚ฌ์šฉํ•˜๊ฒŒ ๋˜๋ฉด ํ”ํžˆ ๋งŒ๋‚˜๊ฒŒ ๋˜๋Š” Exception์ด๋ผ ํ•ด์š”.

์ด ๋ฌธ์ œ๋Š” ๋Œ€๋žต 5๊ฐ€์ง€์˜ ์›์ธ์œผ๋กœ ์ธํ•ด ๋ฐœ์ƒํ•  ์ˆ˜ ์žˆ๋‹ต๋‹ˆ๋‹ค!

 

โ— Mapper Interface์™€ Mapper-XML์˜ ์˜คํƒ€
    - ํ˜น์‹œ Mapper Interface์™€ XML์— ์˜คํƒ€๊ฐ€ ์žˆ๋Š”์ง€ ํ™•์ธ ํ•ด ๋ด์•ผ ํ•˜๋Š” ๊ฒƒ์ด์—์š”.
       <select> ๋ฌธ ๋“ฑ์—์„œ ์„ ์–ธํ•˜๋Š” id ์†์„ฑ ๋ถ€์œ„์— ์˜คํƒ€๊ฐ€ ์žˆ์„์ˆ˜๋„ ์žˆ๊ณ , ์„ ์–ธ๋˜์–ด ์žˆ๋Š” id ์†์„ฑ์ด Mapper Interface
       ์ถ”์ƒ Method์™€ ์ด๋ฆ„์ด ๋‹ค๋ฅธ์ง€ ํ™•์ธํ•ด๋ณด๋Š” ๊ฒƒ์ด์—์š”. Interface ์ด๋ฆ„๊ณผ XML์˜ ์ด๋ฆ„์ด ๋‹ฌ๋ผ์„œ Exception์ด
       ํ„ฐ์งˆ ์ˆ˜ ์žˆ๋Š” ๊ฒƒ์ด์—์š”.

 

 

 

     ๐Ÿ”ฝ  DevInquryMapper.java - devInquryList(DevInquryVO devInquryVO)

 

 

 

 

     ๐Ÿ”ฝ  DevInquryMapper.xml - devInquryList(DevInquryVO devInquryVO)

    <!-- Q&A ๋ชฉ๋ก ์กฐํšŒ -->
    <select id="devInquryList" parameterType="com.devcommunity.junyharang.model.vo.support.DevInquryVO" resultType="com.devcommunity.junyharang.model.vo.support.DevInquryVO">
        select row_number() over(order by i.INQRY_SN asc) as INQRY_INDEX , i.INQRY_SN, i.INQRY_USER_SN , i.FILE_SN , i.INQRY_CN , i.INQRY_SJ , i.SECRET_AT , i.ANSWER_AT , i.ANSWER_CN , i.ANSWER_USER_SN , i.ANSWER_DT , i.CREAT_DT , i.UPDT_DT , i.UPDUSR_SN, u.USER_ID
        from tb_com_inqry i inner join tb_user u
        on i.INQRY_USER_SN = u.user_sn
        where 1=1
        <if test=' srchType neq null and srchType neq "" '>
            <choose>
                <when test="srchType eq '1'.toString()">
                    and INQRY_SJ like CONCAT('%', #{srchWord}, '%')
                </when>
                <when test="srchType eq '2'.toString()">
                    and INQRY_CN like CONCAT('%', #{srchWord}, '%')
                </when>
                <when test="srchType eq '3'.toString()">
                    and u.USER_ID like CONCAT('%', #{srchWord}, '%')
                </when>
            </choose>
        </if>
        order by INQRY_SN desc
        <if test=' pageStart neq null and perPageNum neq null '>
            LIMIT #{pageStart}, #{perPageNum}
        </if>
    </select>

 

 

 

 

     ๐Ÿ”ฝ  DevInquryMapper.java - devInquryReadhitCount(DevInquryVO devInquryVO)

 

 

 

     ๐Ÿ”ฝ  DevInquryMapper.xml - devInquryReadhitCount(DevInquryVO devInquryVO)

 

 

ํžˆ์ง€๋งŒ, ์ฃผ๋‹ˆํ•˜๋ž‘์ด ์ž‘์„ฑํ•œ ๊ฒƒ์„ ๋ณด์•˜์„ ๋•Œ, ์ด ๋ฌธ์ œ๋Š” ์•„๋‹Œ ๊ฒƒ์ด์—์š”.

 

 

โ— mapper-locations
    - Query๊ฐ€ ์ž‘์„ฑ๋œ mapper XML์ด ์œ„์น˜ํ•œ ๊ฒฝ๋กœ๋ฅผ application.properties ํ˜น์€ application.yml์— ์ •์˜๋ฅผ ํ•ด์ค˜์•ผ
      ํ•˜๋Š”๋ฐ, ํ•˜์ง€ ์•Š์•„์„œ ๋ฐœ์ƒํ•  ์ˆ˜๋„ ์žˆ๋Š” ๊ฒƒ์ด์—์š”. ์ •ํ™•ํ•œ ๊ฒฝ๋กœ๋Š” Project์— ๋”ฐ๋ผ ๋ณ€๊ฒฝ ํ•ด ์ฃผ๋ฉด ๋˜๋Š” ๊ฒƒ์ด์—์š”.

 

 

 

 

     ๐Ÿ”ฝ  application.yml

์•„๋ฌด๊ฒƒ๋„ ์ž‘์„ฑ์ด ๋˜์–ด ์žˆ์ง€ ์•Š์€ ๊ฒƒ์ด์—์š”.

 

โ— ๋™์ผํ•œ ์ด๋ฆ„ / ๋‹ค๋ฅธ Packge Path
    - Mapper์˜ ์ด๋ฆ„์€ ๊ฐ™์œผ๋‚˜, Package name์ด ๋‹ฌ๋ผ์„œ IDE์—์„œ Compile Error๊ฐ€ ๋ฐœ์ƒํ•˜์ง€ ์•Š๋Š” ๊ฒฝ์šฐ์ผ ์ˆ˜ ์žˆ๋Š” ๊ฒƒ์ด์—์š”. ์ด๋Ÿฐ ๊ฒฝ์šฐ์—๋Š” Application ๊ตฌ๋™ ๊ณผ์ •์—์„œ Exeption์ด ํ„ฐ์งˆ ์ˆ˜ ์žˆ๋Š” ๊ฒƒ์ด์—์š”. 

 

โ— yaml File ๋‚ด ์˜คํƒ€
    - Project Config(์„ค์ •) File์ธ application์˜ ํ™•์žฅ์ž๊ฐ€ properties๊ฐ€ ์•„๋‹Œ yaml๋กœ ์ž‘์„ฑํ•  ์ˆ˜๋„ ์žˆ๋Š” ๊ฒƒ์ด์—์š”.
      yaml์€ ๊ณ„์ธต ๊ตฌ์กฐ๋กœ ์ž‘์„ฑ๋˜์–ด ๊ฐ€๋…์„ฑ์ด ๋” ์ข‹๋‹ค๋Š” ์žฅ์ ์„ ๊ฐ–๋Š” ๊ฒƒ์ด์—์š”. ๊ทธ๋Ÿฐ๋ฐ, ์•„๋ž˜ ์‚ฌ์ง„๊ณผ ๊ฐ™์ด ๋“ค์—ฌ์“ฐ๊ธฐ ๋“ฑ์„ ์ž˜ ๋ชป
      ๋งž์ถ”๋ฉด Exception์ด ํ„ฐ์ง€๋Š” ๊ฒƒ์ด์—์š”. ์˜ˆ๋ฅผ ๋“ค์ž๋ฉด ์ตœ์ƒ๋‹จ์— ์„ ์–ธ๋œ spring ๋ฐ‘์— ์œ„์น˜ํ•˜๋Š” ๊ฒƒ์ด ์•„๋‹ˆ๋ผ,
     ์ตœ์ƒ๋‹จ์— mybatis๊ฐ€ ์œ„์น˜ํ•ด์•ผ ํ•˜๋Š”๋ฐ, spring ๋ฐ‘์— ์ž‘์„ฑ๋˜์–ด ๋ฒ„๋ฆฌ๋ฉด ๋ฌธ์ œ๊ฐ€ ๋ฐœ์ƒํ•  ์ˆ˜ ์žˆ๋Š” ๊ฒƒ์ด์—์š”.

 

 

โ— DataSource Configuration
   - DataSource๋ฅผ ์„ค์ •ํ•˜๋Š” Configuration Class๋ฅผ ํ•œ๋ฒˆ ์ ๊ฒ€ ํ•ด ๋ณผ ํ•„์š”๊ฐ€ ์žˆ๋Š” ๊ฒƒ์ด์—์š”.
      SessionFactory๊ฐ€ ์„ค์ • ๋˜์–ด ์žˆ๋‹ค๋ฉด setMapperLocations Method ๋“ฑ์œผ๋กœ Mapper XML์˜ ์œ„์น˜๋ฅผ ์„ ์–ธํ•˜๊ฒŒ
      ๋˜๋Š”๋ฐ, ์˜๋„ํ•œ ๋Œ€๋กœ ์ž˜ ์ž‘์„ฑ ๋˜์—ˆ๋Š”์ง€ ํ™•์ธ์ด ํ•„์š”ํ•œ ๊ฒƒ์ด์—์š”. @MapperScan์ด ์„ ์–ธ๋œ ๊ฒฝ์šฐ Mapper Interface๊ฐ€
      ์žˆ๋Š” ์œ„์น˜์™€ ์ผ์น˜ํ•˜๋Š”์ง€๋„ ํ™•์ธ ํ•ด ๋ณผ ํ•„์š”๊ฐ€ ์žˆ๋Š” ๊ฒƒ์ด์—์š”.

 

 

 

 

 

๐Ÿป ๋ฌธ์ œ ํ•ด๊ฒฐ!

๋ฐ˜์‘ํ˜•

๋จผ์ € DataBase์™€ ์—ฐ๊ฒฐ ์ •๋ณด์™€ mybatis๊ด€๋ จ ์„ค์ • ์ •๋ณด๋ฅผ ๋„ฃ์–ด์ค€ ๊ฒƒ์ด์—์š”.

 

 

์ด๋ ‡๊ฒŒ ํ•˜๋‹ˆ ๋ฌธ์ œ๋Š” ๊น”๋”ํ•˜๊ฒŒ ํ•ด๊ฒฐ ๋˜์—ˆ๋‹ต๋‹ˆ๋‹ค!

์ฃผ๋‹ˆํ•˜๋ž‘์€ ๊ฒฐ๊ตญ mapper-locations ์„ค์ •์„ ํ•ด์ฃผ์ง€ ์•Š์•„ ๋ฐœ์ƒํ•œ ๋ฌธ์ œ์˜€๋˜ ๊ฒƒ์ด์—์š”.

 

 

 

 

 

 

 

 

728x90
๋ฐ˜์‘ํ˜•