zoukankan      html  css  js  c++  java
  • <context:annotation-config/>和<mvc:annotation-driven/>及解决No mapping found for HTTP request with URI [/role/getRole] in DispatcherServlet with name 'springmvc-config'

    1:什么时候使用<context:annotation-config>

    当你使用@Autowired,@Required,@Resource,@PostConstruct,@PreDestroy等注解时会选择使用,

    但也可以手动配置Bean来使用这些注解,但是会使spring的配置文件比较笨拙

    一般都会使用<context:annotation-config>,由spring提供,隐式的向容器注册了AutowiredAnnotationBeanPostProcessor,RequiredAnnotationBeanPostProcessor,CommonAnnotationBeanPostProcessor,PersistenceAnnotationBeanPostProcessor这四个bean。

    但是使用注解的时候,我们都会用<xontext:component-scan/>来将bean扫描进容器,此时,可以将<context:annotation-config/>省去

    2:什么时候使用<mvc:annotation-drive/n>

    当使用了@Controller时

    而且是必须使用,如果不使用的话,org.Springframework.web.servlet.DispatcherServlet无法找到控制器并把请求分发到控制器

    <mvc:annotation-driven/>注册了DefaultAnnotationHandleMapping和AnnotationMethodHandleAdapter两个bean(该两个bean解决了@Controller注解的使用前提配置)

    我之前是一个了@Controller注解而没有使用<mvc:annotation-driven/>

    报错:

     No mapping found for HTTP request with URI [/role/getRole] in DispatcherServlet with name 'springmvc-config'
    解决:添加<mvc:annotation-driven/>且必须放在配置文件的第一行
  • 相关阅读:
    shiro源码篇
    python内置模块之collections(六)
    python之自然语言处理入门(一)
    python第三方库之numpy基础
    python算法之近似熵、互近似熵算法
    MongoDB之conf配置文件详解(五)
    MongoDB之主从复制和副本集(四)
    MongoDB之python简单交互(三)
    python设计模式之常用创建模式总结(二)
    python设计模式之单例模式(一)
  • 原文地址:https://www.cnblogs.com/Hdaydayup/p/6622812.html
Copyright © 2011-2022 走看看