报错:classpath resource [com/qinkangdeid/mapping/] cannot be resolved to URL because it does not exist

参考: http://www.jianshu.com/p/800fe918cc7a
ssm整合的时候报错:

Caused by: java.lang.IllegalArgumentException: Could not resolve resource location pattern [classpath:com/qinkangdeid/mapping/*.xml]: class path resource [com/qinkangdeid/mapping/] cannot be resolved to URL because it does not exist

at org.springframework.core.io.support.ResourceArrayPropertyEditor.setAsText(ResourceArrayPropertyEditor.java:140)
    at org.springframework.beans.TypeConverterDelegate.doConvertTextValue(TypeConverterDelegate.java:430)
    at org.springframework.beans.TypeConverterDelegate.doConvertValue(TypeConverterDelegate.java:403)
    at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:181)
    at org.springframework.beans.BeanWrapperImpl.convertIfNecessary(BeanWrapperImpl.java:459)
    ... 72 more

这里写图片描述
解决:
在配置文件下 扫描不到 xml文件:
原来的文件:

<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
    <property name="dataSource" ref="dataSource"/>
    <!-- 自动扫描mapping.xml文件 -->
    <property name="mapperLocations" value="classpath:com/qinkangdeid/mapping/*.xml"/>
</bean>

修改classpath 为 classpath*

<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
    <property name="dataSource" ref="dataSource"/>
    <!-- 自动扫描mapping.xml文件 -->
    <property name="mapperLocations" value="classpath*:com/qinkangdeid/mapping/*.xml"/>
</bean>

运行测试:又出现另外的报错:
org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.qinkangdeid.dao.UserMapper.selectByPrimaryKey
这里写图片描述

解决:
war包里面缺少Mapper对应的xml文件,也就是没有把xml文件打包进去。解决办法是,在pom.xml文件中的build标签中添加如下代码,显示的强制将xml文件打到war包中:

这里写图片描述

 <!--  强制将xml文件打到war包中 s-->
        <resources>
            <resource>
                <directory>src/main/java</directory>
                <includes>
                    <include>**/*.xml</include>
                </includes>
                <filtering>false</filtering>
            </resource>
        </resources>

重新测试,成功:
这里写图片描述

没有更多推荐了,返回首页