Caused by: org.apache.ibatis.binding.BindingException:
Invalid bound statement (not found): com.xxx.xxx.xxx.monitor.mapper.XXXXMapper.loadAllServices
at org.apache.ibatis.binding.MapperMethod$SqlCommand.<init>
(MapperMethod.java:189) ~[mybatis-3.2.7.jar:3.2.7]
at org.apache.ibatis.binding.MapperMethod.<init>
(MapperMethod.java:43) ~[mybatis-3.2.7.jar:3.2.7]
at org.apache.ibatis.binding.MapperProxy.
cachedMapperMethod(MapperProxy.java:58) ~[mybatis-3.2.7.jar:3.2.7]
at org.apache.ibatis.binding.MapperProxy.
invoke(MapperProxy.java:51) ~[mybatis-3.2.7.jar:3.2.7]
at com.sun.proxy.$Proxy35.
loadAllServices(Unknown Source) ~[na:na]
...
...
at sun.reflect.DelegatingMethodAccessorImpl.
invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.7.0_79]
at java.lang.reflect.Method.
invoke(Method.java:606) ~[na:1.7.0_79]
at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleElement.
invoke(InitDestroyAnnotationBeanPostProcessor.java:354) ~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleMetadata.
invokeInitMethods(InitDestroyAnnotationBeanPostProcessor.java:305) ~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.
postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:133) ~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE]
... 74 common frames omitted
分析了好一大陣后才發現是maven編譯時的配置出問題,加上下面這個配置就好了
<build>
...
<resources>
<resource>
<directory>src/main/resources</directory>
<excludes>
<exclude>**/.svn/*</exclude>
</excludes>
</resource>
<resource>
<directory>src/main/java</directory>
<excludes>
<exclude>**/.svn/*</exclude>
</excludes>
<includes>
<include>**/*.xml</include>
</includes>
</resource>
</resources>
...
</build>
原因在於如果你的資源文件在java包下面,則maven默認打包是不會認為這些資源文件需要打入包內,所以在啟動的時候老是會報Invalid bound statement (not found),而如果資源文件放在resources文件夾下面就不會有問題,這與maven的資源存放機制有關。如果要求maven打包的時候將java包下面的非*.java文件也打入包中,則需要上面這這個配置項。
主要參考:http://www.lpnote.com/2016/03/04/mybatis-invalid-bound-statement-not-found/