1.当出现以下错误:
Error creating bean with name 'sqlSessionFactory' defined in class path resource [spring-mybatis.xml]: Initialization of bean failed; nested exception is org.springframework.beans.TypeMismatchException: Failed to convert property value of type [java.lang.String] to required type [org.springframework.core.io.Resource[]] for property 'mapperLocations'; nested exception is java.lang.IllegalArgumentException: Could not resolve resource location pattern [classpath:com/mapping/*Mapper.xml]: class path resource [com/mapping/] cannot be resolved to URL because it does not exist
错误原因:这是出现了,没有扫描导bean,com/mapping这个源没有扫描到。
一开始我是写成这样的
<!-- 自动扫描mapping.xml文件 -->
<property name="mapperLocations" value="classpath:com/mapping/*Mapper.xml"></property>
因为是看网上搭建框架的步骤一步步来的,很多复制黏贴,所以有些错误无法自己找出。
这里如果无法扫描到,请修改成这样。
<!-- 自动扫描mapping.xml文件 -->
<property name="mapperLocations" value="classpath*:com/mapping/*Mapper.xml"></property>
加个星号就行了。。。
2.maven引入包的问题
引入net.sf.json-lib包一直失败,依赖是这样的。
<dependency>
<groupId>net.sf.json-lib</groupId>
<artifactId>json-lib</artifactId>
<version>2.4</version>
</dependency>
看了网上的一些答案说是加入jdk15,因为这个包就是jdk15的。
<dependency>
<groupId>net.sf.json-lib</groupId>
<artifactId>json-lib</artifactId>
<version>2.4</version>
<classifier>jdk15</classifier>
</dependency>
修改成这样就可以了。
还有一种情况就是,引入了同样类型的包,例如
先引入了这个alibb的fastjson包
import com.alibaba.fastjson.JSONObject;
未完待续。。。。