1
|
<context:component-scan base-
package
=「com.test" />
|
HandlerMapping,是SpringMVC中用來處理Request請求URL到具體Controller的,其自身也分紅不少種類;
HandlerAdapter,是SpringMVC中用來處理具體請求映射到具體方法的,其自身也分不少種類;
@RequestMapping這個註解的主要目的就是對具體的Controller和方法進行註冊,以方便HandlerMapping用來處理請求的映射。可是@RequestMapping須要結合<mvc:annotation-driven />使用才能生效。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
protected
void
initHandlerMethods() {
if
(logger.isDebugEnabled()) {
logger.debug(
"Looking for request mappings in application context: "
+ getApplicationContext());
}
String[] beanNames = (
this
.detectHandlerMethodsInAncestorContexts ?
BeanFactoryUtils.beanNamesForTypeIncludingAncestors(getApplicationContext(), Object.
class
) :
getApplicationContext().getBeanNamesForType(Object.
class
));
for
(String beanName : beanNames) {
if
(isHandler(getApplicationContext().getType(beanName))){
detectHandlerMethods(beanName);
}
}
handlerMethodsInitialized(getHandlerMethods());
}
|
1
2
3
|
protected
boolean
isHandler(Class<?> beanType) {
return
AnnotationUtils.findAnnotation(beanType, Controller.
class
) !=
null
;
}
|
1
2
3
4
5
|
<bean
class
=
"org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping"
>
<property name=
"detectHandlerMethodsInAncestorContexts"
>
<value>
true
</value>
</property>
</bean>
|
Spring容器配置,排除全部@controller的Bean
1
2
3
|
<context:component-scan base-
package
=
"com.fsnip.open"
>
<context:exclude-filter type=
"annotation"
expression=
"org.springframework.stereotype.Controller"
/>
</context:component-scan>
|
SpringMVC容器配置,讓其只包括@controller的Bean
1
2
3
|
<context:component-scan base-
package
=
"com.fsnip.open"
use-
default
-filters=
"false"
>
<context:include-filter type=
"annotation"
expression=
"org.springframework.stereotype.Controller"
/>
</context:component-scan>
|
轉載開濤博客html