SSM框架防入坑步骤四

2018-07-08  本文已影响0人  ThinkingInDay

1.如果在Controller层中返回页面失败了:

首先看web.xml中servlet-mapping中url-pattern:是/而不是/*

原因:

< url-pattern > / 不会匹配到*.jsp,即:*.jsp不会进入spring的 DispatcherServlet类 。

< url-pattern > /*  会匹配*.jsp,会出现返回jsp视图时再次进入spring的DispatcherServlet 类,导致找不到对应的controller所以报404错。

2.如果当你启动tomcat时报错:错误是这样的

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'studentController': Unsatisfied dependency expressed through field 'studentDao'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.dao.StudentDao' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}。。。。。。。

Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.dao.StudentDao' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}

解决办法:请查看mapper文件下:StudentMapper.xml中的mapper namespace填写的dao的路径对吗?

上一篇下一篇

猜你喜欢

热点阅读