解决Maven项目下使用Mybatis时,找不到mapper映射文件(不拷贝)问题

问题

解决Maven项目下使用Mybatis时,找不到mapper映射文件(不拷贝)问题_第1张图片
控制台输出错误信息:

六月 25, 2018 2:23:26 下午 org.apache.catalina.core.StandardWrapperValve invoke
严重: Servlet.service() for servlet [taotao-manager] in context with path [] threw exception [Request processing failed; nested exception is org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.taotao.mapper.TbItemMapper.selectByExample] with root cause
org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.taotao.mapper.TbItemMapper.selectByExample
    at org.apache.ibatis.binding.MapperMethod$SqlCommand.(MapperMethod.java:189)
    at org.apache.ibatis.binding.MapperMethod.(MapperMethod.java:43)
    at org.apache.ibatis.binding.MapperProxy.cachedMapperMethod(MapperProxy.java:58)
    at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:51)
    at com.sun.proxy.$Proxy31.selectByExample(Unknown Source)
    at com.taotao.service.impl.ItemServiceImpl.getItemById(ItemServiceImpl.java:31)
    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)
    ..

原因

从这里看出,mapper接口与mapper映射文件放在同一包下
解决Maven项目下使用Mybatis时,找不到mapper映射文件(不拷贝)问题_第2张图片
但是编译后,classes下只有.class文件,而没有mapper映射文件,导致调用mapper接口时找不到映射文件
解决Maven项目下使用Mybatis时,找不到mapper映射文件(不拷贝)问题_第3张图片

方法

修改pom.xml文件


<build>
    <plugins>
        
        <plugin>
            <groupId>org.apache.maven.pluginsgroupId>
            <artifactId>maven-resources-pluginartifactId>
            <version>2.7version>
            <configuration>
                <encoding>UTF-8encoding>
            configuration>
        plugin>
    plugins>
    <resources>
         <resource>
             <directory>src/main/javadirectory>
             <includes>
                 <include>**/*.propertiesinclude>
                 <include>**/*.xmlinclude>
             includes>
             <filtering>falsefiltering>
         resource>
     resources>
build>

结果

解决Maven项目下使用Mybatis时,找不到mapper映射文件(不拷贝)问题_第4张图片
解决Maven项目下使用Mybatis时,找不到mapper映射文件(不拷贝)问题_第5张图片

你可能感兴趣的:(【工具】Maven,【框架】Mybatis)