天天看點

Spring component detection logicCreated by Wang, Jerry, last modified on Jul 25, 2016

Created by Wang, Jerry, last modified on Jul 25, 2016

Spring component detection logicCreated by Wang, Jerry, last modified on Jul 25, 2016

在xml配置了這個标簽後,spring可以自動去掃描base-pack下面或者子包下面的java檔案,如果掃描到有@Component @Controller@Service 等這些注解的類,則把這些類注冊為bean

Spring component detection logicCreated by Wang, Jerry, last modified on Jul 25, 2016
http://www.cnblogs.com/haoke/p/4604883.html

<

context:component-scan

base-package

=“com.fq”

context:exclude-filter

type

=“annotation”

expression

=“org.springframework.stereotype.Controller”

/>

可以看到,他是要掃描com.fq包下的所有子類,不包含@Controller。對于exculude-filter不存在包不精确後都進行掃描的問題。

Spring component detection logicCreated by Wang, Jerry, last modified on Jul 25, 2016
Spring component detection logicCreated by Wang, Jerry, last modified on Jul 25, 2016
Spring component detection logicCreated by Wang, Jerry, last modified on Jul 25, 2016
Spring component detection logicCreated by Wang, Jerry, last modified on Jul 25, 2016
Spring component detection logicCreated by Wang, Jerry, last modified on Jul 25, 2016
Spring component detection logicCreated by Wang, Jerry, last modified on Jul 25, 2016

@RequestMapping

RequestMapping是一個用來處理請求位址映射的注解,可用于類或方法上。用于類上,表示類中的所有響應請求的方法都是以該位址作為父路徑。

1、 value, method;

value: 指定請求的實際位址,指定的位址可以是URI Template 模式

Spring component detection logicCreated by Wang, Jerry, last modified on Jul 25, 2016

@responsebody表示該方法的傳回結果直接寫入HTTP response body中

一般在異步擷取資料時使用,在使用@RequestMapping後,傳回值通常解析為跳轉路徑,加上@responsebody後傳回結果不會被解析為跳轉路徑,而是直接寫入HTTP response body中。比如異步擷取json資料,加上@responsebody後,會直接傳回json資料。

Spring component detection logicCreated by Wang, Jerry, last modified on Jul 25, 2016