1.Spring
2.MyBatis
2.1MyBatis配置错误
2.1.1 UTF-8错误
Exception in thread “main”
org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException:
Line 36 in XML document from class path resource [spring-cfg4.xml] is
invalid; nested exception is org.xml.sax.SAXParseException;
lineNumber: 36; columnNumber: 11; 2 字节的 UTF-8 序列的字节 2 无效。
报错如上,原因是
将UTF-8写成UTF8
或者在pom.xml中进行一项配置
<properties> <!--这一行能够保证mybatis-config.xml不出错--> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties>
2.1.2 mybatis-config.xml找不到错误
Exception in thread “main” org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [spring-cfg4.xml]; nested exception is java.io.FileNotFoundException: class path resource [spring-cfg4.xml] cannot be opened because it does not exist
如果你的mybatis-config.xml没有放在resources文件夹下,那么在编译的时候,不会将xml和properties文件编译进去。
在pom.xml中进行配置
<build> <resources> <resource> <directory>src/main/java</directory> <includes> <include>**/*.properties</include> <include>**/*.xml</include> </includes> <filtering>true</filtering> </resource> </resources> </build>