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/>且必须放在配置文件的第一行
  • 相关阅读:
    柔性的沟通
    as3简单的文字提示队列
    恢复低版本的FlashPlayer
    AIR切换SDK版本时遇到的问题
    文字闪烁提示
    as3 ISOLIB学习资料整理
    xml文件转二进制文件的AIR
    Photoshop CS5的序列号
    MySQL导出、导出数据
    as3 shake动画
  • 原文地址:https://www.cnblogs.com/Hdaydayup/p/6622812.html
Copyright © 2011-2022 走看看