1. 程式人生 > 其它 >解決Could not find resource mybatis-config.xml的問題

解決Could not find resource mybatis-config.xml的問題

先看一點錯誤資訊吧

錯誤編碼:
``java.io.IOException: Could not find resource mybatis-config.xml at org.apache.ibatis.io.Resources.getResourceAsStream(Resources.java:114) at org.apache.ibatis.io.Resources.getResourceAsStream(Resources.java:100) at com.ahau.pms.utils.SqlSessionUtil.(SqlSessionUtil.java:23) at com.ahau.pms.settings.service.impl.UserServiceImpl.(UserServiceImpl.java:19)

at com.ahau.pms.settings.web.controller.UserController.login(UserController.java:65) at com.ahau.pms.settings.web.controller.UserController.service(UserController.java:29) at javax.servlet.http.HttpServlet.service(HttpServlet.java:764) 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:52) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at com.ahau.pms.web.filter.LoginFilter.doFilter(LoginFilter.java:28) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at com.ahau.pms.web.filter.EncodingFilter.doFilter(EncodingFilter.java:16) 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:196) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:97) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:542) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:135) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81) at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:698) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:78) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:364) at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:624) at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65) at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:831) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1673) at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) at org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1191) at org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Thread.java:748)

解決

我的mybatis-config.xml放在resources資料夾

——>依賴mybatis-config.xml的sqlSession配置錯誤——>果然resource匯入的mybatis-config位置錯誤

測試,

依然無法找到mybatis-config.xml——>檢查打包後是否資源丟失,經檢查果然target包無mybatis-config.xml檔案

——>在pom.xml中設定資源引用,防止資源在打包時丟失——>測試,依然無法找到——>進一步聚焦到該配置是否有問題

——>resource配置裡用的exclude,這神仙也導不進來,改為include

測試成功,以下為正確設定

——>教訓:聽課吃癟的地方:注意關鍵節點名詞的出現,和它的意義,以及一些具體配置在使用別人的時,要知其所以然