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/>且必须放在配置文件的第一行

<context:annotation-config/>和<mvc:annotation-driven/>及解决No mapping found for HTTP request with URI [/role/getRole] in DispatcherServlet with name 'springmvc-config'的更多相关文章

  1. No mapping found for HTTP request with URI异常的原因,<mvc:default-servlet-handler/>的作用

    一.最近做的一个项目有很多静态资源文件,按照平时的配置springmvc进行配置发现访问不到静态文件,并且在我配置好controller去访问结果还是404 No mapping found for ...

  2. No mapping found for HTTP request with URI [/HelloWeb/] in DispatcherServlet with name 'HelloWeb' Spring MVC

    I'm learning the Spring Framework, and I'm doing the HelloWeb tutorial on tutorialspoint, and I can' ...

  3. spring mvc No mapping found for HTTP request with URI [/web/test.do] in DispatcherServlet with name 'spring'

    原因: spring-servlet.xml 中 <context:component-scan base-package="com.test.controller" /&g ...

  4. Spring MVC --->>>No mapping found for HTTP request with URI

    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> < ...

  5. Spring MVC PageNotFound.noHandlerFound No mapping found for HTTP request with URI

    首先骂人,干他娘的,弄了两个小时原来的包倒错了!!唉TMD. 注意用IDEA倒包的时候一定要注意ModelAndView是 原因是import出错了!!应该是import org.springfram ...

  6. Spring Boot, Java Config - No mapping found for HTTP request with URI [/…] in DispatcherServlet with name 'dispatcherServlet'

    Spring Boot 启用应用: error: No mapping found for HTTP request with URI [/…] in DispatcherServlet with n ...

  7. Spring MVC 使用问题与解决--HTTP Status 500 - Servlet.init() for servlet springmvc threw exception

    1.HTTP Status 500 - Servlet.init() for servlet springmvc threw exception 解决 使用jre1.7 Spring4.3 2.spr ...

  8. spring3 jsp页面使用<form:form modelAttribute="xxxx" action="xxxx">报错,附连接数据库的spring MVC annotation 案例

    在写一个使用spring3 的form标签的例子时,一直报错,错误信息为:java.lang.IllegalStateException: Neither BindingResult nor plai ...

  9. Spring 一二事(8) - annotation 形式的 MVC

    <!-- component:把一个类放入到spring容器中,该类就是一个component 在base-package指定的包及子包下扫描所有的类 --> <context:co ...

随机推荐

  1. Building Fire Stations ZOJ - 3820 (二分,树的直径)

    大意: 给定树, 求两个点, 使得所有其他的点到两点的最短距离的最大值尽量小. 二分答案转为判定选两个点, 向外遍历$x$的距离是否能遍历完整棵树. 取直径两段距离$x$的位置bfs即可. #incl ...

  2. Alyona and a tree CodeForces - 739B (线段树合并)

    大意: 给定有根树, 每个点$x$有权值$a_x$, 对于每个点$x$, 求出$x$子树内所有点$y$, 需要满足$dist(x,y)<=a_y$. 刚开始想错了, 直接打线段树合并了..... ...

  3. Spring boot @Autowired注解在非Controller中注入为null

    参考链接:https://blog.csdn.net/qq_35056292/article/details/78430777

  4. loj#528. 「LibreOJ β Round #4」求和

    求:\(\sum_{i=1}^n\sum_{j=1}^m\mu(gcd(i,j))^2\) 化简可得\(\sum_{i=1}^{min(n,m)}{\lfloor \frac{n}{i} \rfloo ...

  5. Matlab-1:jacobi迭代法工具箱

    function [u,n]=Jacobi(A,b,u0,eps,varargin) %Jacobi.m函数为用于雅可比迭代法求解线性方程组 %A为线性方程组的系数矩阵 %b为线性方程组的常数向量 % ...

  6. 使用navigator.userAgent.toLowerCase()判断移动端类型

    使用navigator.userAgent.toLowerCase()判断移动端类型 判断设备,区分Android,iphone,ipad和其它 var ua = navigator.userAgen ...

  7. CRM BP SEARCH 优化

    出于方便的目的,这边将BU_GROUP,SALE_ORG加到了BP搜索里面,因为CRM项目推广了很多国家,每个国家一个SALE ORG,而标准的BP HEADER ADV SEARCH里竟然没有BU_ ...

  8. 1013. Pairs of Songs With Total Durations Divisible by 60总持续时间可被 60 整除的歌曲

    网址:https://leetcode.com/problems/pairs-of-songs-with-total-durations-divisible-by-60/submissions/ 参考 ...

  9. Spring注解之@validated的使用

    spring-boot中可以用@validated来校验数据,如果数据异常则会统一抛出异常,方便异常中心统一处理.比如,我们判断一个输入参数是否合法,可以用如下方式 一 基础使用 因为spring-b ...

  10. @NotNull, @NotEmpty和@NotBlank之间的区别是什么?

    首先是简要描述: [java] view plain copy@NotNull://CharSequence, Collection, Map 和 Array 对象不能是 null, 但可以是空集(s ...