1、sqlSessionFactory创建失败
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘sqlSessionFactory’ defined in class path resource [conf/spring-mybatis.xml]:
好像是说在spring-mybatis.xml中注册configLocation的地方有错
<!--<!– spring和MyBatis完美整合,不需要mybatis的配置映射文件 –>-->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<!-- 自动扫描mapping.xml文件 -->
<property name="mapperLocations" value="classpath:com/web/dev/mapper/*.xml"></property>
</bean>
后来查了一下,classpath后面需要加一个*号,正确的如下:
<!--<!– spring和MyBatis完美整合,不需要mybatis的配置映射文件 –>-->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<!-- 自动扫描mapping.xml文件 -->
<property name="mapperLocations" value="classpath*:com/web/dev/mapper/*.xml"></property>
</bean>
2、报找不到xml配置文件
org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.web.dev.dao.WebsitesMapper.queryList
进入编译后的class文件夹中查看,发现mapper.xml文件并为编辑成功;
后经查询发现,
注意:
在使用IDEA开发时,如果打包时*Mapper.xml没有自动复制到class输出目录的mapper类包下,则需要在pom文件中添加mybatis加载配置文件的配置!
如下
<build>
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.xml</include>
</includes>
</resource>
<resource>
<directory>src/main/resources</directory>
</resource>
</plugins>
</build>
本人的问题就是IDEA下碰到的,在pom文件中添加mybatis加载配置文件然后就完美解决了,感谢互联网资源~
复制上述代码时,pom文件可能报:
Element ‘beans’ cannot have character [children], because the type’s content type is element-only.错误。
就是这些从网页上直接复制下来的眼睛看不到的字符导致了这个错误!
要是看不出来改一下编码格式,如ANSI编码!
或事直接手动修改编写就行
3、java.lang.IllegalArgumentException错误
java.lang.IllegalArgumentException: Result Maps collection already contains value for com.web.dev.da
这个为mapper.xml文件中的id有重复的,仔细查看一下是否有重复的id命名即可