项目编译时没报错,启动tomcat报错如下:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in class path resource [spring-mybatis.xml]: Invocation of init method failed; nested exception is org.springframework.core.NestedIOException: Failed to parse mapping resource: 'file [F:\Java_Tools_Install_Lacation\tomcate_location\tomcat7.5.57\apache-tomcat-7.0.57\webapps\Capacity\WEB-INF\classes\com\hans\mapper\UserMapper.xml]'; nested exception is org.apache.ibatis.builder.BuilderException: Error parsing Mapper XML. Cause: org.apache.ibatis.builder.BuilderException: Error resolving class. Cause: org.apache.ibatis.type.TypeException: Could not resolve type alias 'com.hans.entity.User'. Cause: java.lang.ClassNotFoundException: Cannot find class: com.hans.entity.User
究其原因,就是项目扫描mapper文件的时候,不能识别 com.hans.entity.User 这个类,而实际上这个类是存在的。
分析下来只能是tomcat没编译文件了......
解决方法很简单,点开Project > Build Automatically 打上√,然后再Clean一下,重启tomcat,运行正常。