在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/Java/ <context:component-scan base-package=

<context:component-scan base-package=""/>會掃描@RequestMapping注解嗎?

測試了一下,貌似是可以的,只需要在Spring mvc的配置文件中寫上:
    <context:component-scan base-package="..."/>
貌似@Controller,@RequestMapping注解就可以使用了. 

此外,<context:component-scan base-package=""/>是應(yīng)該配置在Spring配置文件中,
還是應(yīng)該配置在Spring mvc的配置文件中,或者是兩個文件中都需要配置呢?   
回答
編輯回答
大濕胸

spring mvc有個默認(rèn)的DefaultAnnotationHandlerMapping 來處理RequestMapping

spring與spring mvc 是兩個不同的容器,spring是父容器,spring mvc是子容器。那么,子容器是可以訪問父容器的bean,父容器不能訪問子容器的bean。

  1. 在spring中配置全局掃描:spring容器就包含了所有bean,spring mvc沒有bean,那么加載處理器,映射器,就會找不到映射對象,映射關(guān)系,頁面404
  2. 在spring mvc中配置全局掃描:spring mvc容器包含了所有bean,相當(dāng)于spring容器 沒有作用,里面的bena就是普通的bean,那你的事務(wù)處理怎么辦呢 諸如此類spring相關(guān)操作?

所以說 兩個框架配置文件 各自按需配置。

2017年11月10日 03:12