我当时检查了下面的所有内容发现都没有错,最后在第五个监听器打错了,这给我气的。大家自己对照下面的内容仔细看看自己哪里错了吧
类检查方面:
1.是否在加了@Controller @Repository @Service 注解
@Controller
@RequestMapping(value = "/user")
public class UserController {
@Service
public class UserServiceImpl implements UserService{
@Repository
public interface UserDao {
2.spring-mvc的配置中 是否自动注册了controller类
<mvc:annotation-driven />
<context:component-scan base-package="lf.controllers"/>
3.spring的配置中,是否注册了用到的类
<context:annotation-config/>
<context:component-scan base-package="lf">
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
</context:component-scan>
4.如果用了mybatis,看看配置的路径是否正确
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="mapperLocations" value="classpath:mapper/*.xml"/>
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="lf.dao"/>
<!--<property name="sqlSessionFactoryBeanName" value="lazySqlSessionFactory"/>-->
</bean>
mapper的namespace是否正确
<mapper namespace="lf.dao.UserDao">
<resultMap id="BaseResultMap" type="lf.model.User">
<id property="id" column="id"/>
如果还跑不起来,就可能是web.xml里面丢了listener
5.我当时项目调了两天也没出来,也是百度了好久发现真的是五花八门,结果是打监听器的时候打错了包,我写成了这个,结果就一直报这个错,大家一定检查你的监听器
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
我的目录如下