SpringMvc自动装配@Controller无效
1.问题原因:SpringMvc驱动器没有扫描该Controller层
虽然配置了
<!-- 启用spring mvc 注解 -->
<context:annotation-config /> <!-- 设置使用注解的类所在的jar包 -->
<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无效的更多相关文章
- 基于注解整合struts2与spring的时候如果不引入struts2-spring-plugin包自动装配无效
基于注解整合struts2与spring的时候如果不引入struts2-spring-plugin包,自动装配将无效,需要spring注入的对象使用时将抛出空指针异常(NullPointerExcep ...
- SSM-SpringMVC-18:SpringMVC中参数自动装配
------------吾亦无他,唯手熟尔,谦卑若愚,好学若饥------------- 在处理方法中,参数写上之后,只要符合特定规则,就可以自动装配 首先 其次是:自定义的参数的自动装配: 案例如 ...
- spring作用、spring注解、管理对象的作用域与生命周期、自动装配、Spring的框架包有哪些作用是什么
Spring 1. 作用 创建和管理对象,使得开发过程中,可以不必使用new关键字创建对象,而是直接获取对象!并且,还可以通过一些配置,使得某些获取到的对象,其中某些属性已经是被赋值的! 2. Spr ...
- SpringMVC常用注解@Controller,@Service,@repository,@Component
SpringMVC常用注解@Controller,@Service,@repository,@Component controller层使用@controller注解 @Controller 用于标记 ...
- Spring 自动装配及其注解
一.属性自动装配 首先,准备三个类,分别是User,Cat,Dog.其中User属性拥有Cat和Dog对象. package com.hdu.autowire; public class User { ...
- IDEA02 利用Maven创建Web项目、为Web应用添加Spring框架支持、bean的创建于获取、利用注解配置Bean、自动装配Bean、MVC配置
1 环境版本说明 Jdk : 1.8 Maven : 3.5 IDEA : 专业版 2017.2 2 环境准备 2.1 Maven安装及其配置 2.2 Tomcat安装及其配置 3 详细步骤 3.1 ...
- 导图梳理springboot手动、自动装配,让springboot不再难懂
什么是springboot 在学springboot之前,你必须有spring.spring mvc基础,springboot的诞生其实就是用来简化新Spring应用的初始搭建以及开发过程,该框架使用 ...
- SpringMVC常用注解@Controller,@Service,@repository,@Component,@Autowired,@Resource,@RequestMapping
1.controller层使用@Controller注解-用于呈现层,(spring-mvc) @Controller 用于标记在一个类上,使用它标记的类就是一个SpringMVC Controlle ...
- SpringBoot核心特性之组件自动装配
写在前面 spring boot能够根据依赖的jar包自动配置spring boot的应用,例如: 如果类路径中存在DispatcherServlet类,就会自动配置springMvc相关的Bean. ...
随机推荐
- UWP: 实现 UWP 应用自启动
在上一篇文章中,我们实现了使用命令行来启动 UWP 应用,在这一篇文章中,我们会实现 UWP 应用自启用的实现,也即开机后或用户登陆后,应用自己启动.这些特性原来都是 Win32 程序所具备的,UWP ...
- 程序员之殇 —— One program, One king (血月)
Are we living in the time of the end? (程序员的时代是否已经终结了?) 最近,我时常问自己这个问题. 刚读完了一个美国博士的论文,UDT (UDP-based D ...
- 一种CListCtrl自绘效果
- localhost或本机ip无法连接数据库问题解决与原因
解决办法:将localhost替换为127.0.0.1 原因@参考文章:navicat在电脑没有联网的情况下,并不会把localhost解析成127.0.0.1,而mysql默认情况下只支持127.0 ...
- 错误:You can't specify target table 'xxx' for update in FROM clause的解决
问题: 今天在MySQL数据库删除重复数据的时候遇到了一个问题.如下脚本: DELETE FROM tempA WHERE tid IN ( SELECT MAX(tid) AS tid FROM t ...
- ClearCase新增文件
原文地址:http://blog.csdn.net/ace_fei/article/details/7531376 大家应该都知道在clearcase上新增文件是通过以下过程来生成的: clearto ...
- IO (二)
1 字符流的缓冲区 缓冲区的出现提高了对数据的读写效率. 对应的类: BufferedWriter BufferedReader 缓冲区要结合流才能使用. 在流的基础上对流的功能进行了增强. 2 Bu ...
- 编译原理:基于状态转换图识别for语句
int state =0;while(state<9){ switch state{ case 0: if(ch=='f'){ state=1;getchar(ch); } case 1: if ...
- 【转】Vim使用笔记
http://www.cnblogs.com/jiqingwu/archive/2012/06/14/vim_notes.html 曾经使用了两年多的Vim,手册也翻过一遍.虽然现在不怎么用vim了, ...
- Codeforce A. Quasi-palindrome
A. Quasi-palindrome time limit per test 1 second memory limit per test 256 megabytes input standard ...