springboot+mybatis项目启动时,有异常信息如下:
Property 'mapperLocations' was not specified.
接口访问时报错如下:
org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.test.mapper.TestMapper.getTest
at org.apache.ibatis.binding.MapperMethod$SqlCommand.<init>(MapperMethod.java:235)
at org.apache.ibatis.binding.MapperMethod.<init>(MapperMethod.java:53)
at org.apache.ibatis.binding.MapperProxy.lambda$cachedMapperMethod$0(MapperProxy.java:62)
at java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1660)
at org.apache.ibatis.binding.MapperProxy.cachedMapperMethod(MapperProxy.java:62)
at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:57)
at com.sun.proxy.$Proxy141.getTest(Unknown Source)
at com.test.service.impl.TestServiceImpl.getTest(TestServiceImpl.java:28)
at com.test.controller.TestController.getTest(TestController.java:34)
原因是:未找到mapper.xml文件
解决方案:
1、将mapper.xml文件放到resources目录下
2、pom.xml文件中加上<resources>,接口可成功访问
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.xml</include>
</includes>
<filtering>false</filtering>
</resource>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.*</include>
</includes>
<filtering>false</filtering>
</resource>
</resources>