码迷,mamicode.com
首页 > 编程语言 > 详细

SpringMvc自动装配@Controller无效

时间:2017-04-09 13:01:42      阅读:220      评论:0      收藏:0      [点我收藏+]

标签:config   解决办法   servlet   spring   ext   efault   http   location   驱动器   

1.问题原因:SpringMvc驱动器没有扫描该Controller层

虽然配置了

1     <!-- 启用spring mvc 注解 -->
2     <context:annotation-config />
3 
4     <!-- 设置使用注解的类所在的jar包 -->
5     <context:component-scan base-package="cn.lonecloud.controller"></context:component-scan>

但是由于没有启用mvc驱动器导致其自动装配失败

解决办法:

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">

    <mvc:annotation-driven />
    <mvc:default-servlet-handler />
    <!-- 启用spring mvc 注解 -->
    <context:annotation-config />

    <!-- 设置使用注解的类所在的jar包 -->
    <context:component-scan base-package="cn.lonecloud.controller"></context:component-scan>
</beans>

添加

<mvc:annotation-driven />
    <mvc:default-servlet-handler />和mvc的schema文件即可开启驱动

SpringMvc自动装配@Controller无效

标签:config   解决办法   servlet   spring   ext   efault   http   location   驱动器   

原文地址:http://www.cnblogs.com/lonecloud/p/6684064.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!