下面是我这几天整合SpringMVC+Spring+MyBatis框架遇到的一些问题 ,在这里总结一下:
1:HTTP Status 500 - Request processing failed; nested exception is org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException:
问题是:数据库连接出错,一般是配置数据库连接的url、username、password或者是数据库连接失败
url配置:jdbc:mysql://数据库地址:端口号/数据库名?编码等 //如:url=jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf-8
2:HTTP Status 500 - Servlet.init() for servlet SpringMVC threw exception
....(此处省略上上重点错误,如下:)
root cause
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException:
Could not autowire field: com.service.UserService com.controller.UserController.userService; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.service.UserService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
问题是:业务层没有@Service注解
提示大概的意思是controller里的的UserService自动注入失败
3:[spring]启动时报错:NoSuchMethodError: javax.servlet.http.HttpServletResponse.getStatus()I
Spring V4.1.0+的版本在不支持Servlet3.0的应用服务器上跑时会报以下错误:
NoSuchMethodError: javax.servlet.http.HttpServletResponse.getStatus()I
比如说:tomcat 7以下的版本、jboss 4.2.3以下的版本
解决版本有两个(任意选一个即可):
1)、退回到Spring V4.0.7
2)、升级应用服务器到支持Servlet3的应用服务器。
比如tomcat7+(最好是tomcat8+)、jboss as 7+
4:java.lang.NoClassDefFoundError: org/springframework/core/MethodIntrospector$MetadataLookup
1)、我这里出现的问题好像是spring-core和其它包发生冲突了,我删了spring-core包后重启IDEA就可以了。
5:在使用Mbatis逆向工程的时间,运行时报:Failed to execute goal org.mybatis.generator:mybatis-generator-maven-plugin:1.3.2:generate (default-cli) on project shop: Execution default-cli of goal org.mybatis.generator:mybatis-generator-maven-plugin:1.3.2:generate failed:
Cannot resolve classpath entry: C:\Users\Administrator.SC-201810221720\.m2\repository\mysql\mysql-connector-java\5.1.27\mysql-connector-java-5.1.27.jar} -> [Help 1]
大致意思应该是mysql驱动包连接不到。
这里就是generatorConfig.xml文件中的classPathEntry路径配置错误,这里范了个很低级的错误,最后那里多了个方括号(“}”)