【springMVC】源码如何组装springMvc的原理
一、配置
<context:component-scan base-package="*.controller"/> <!-- 处理在类级别上的@RequestMapping注解 --> <bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping"> </bean> <bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter"> <property name="messageConverters"> <list> <bean class="org.springframework.http.converter.StringHttpMessageConverter"> <property name="supportedMediaTypes"> <list> <value>text/html;charset=UTF-8</value> <value>text/plain;charset=UTF-8</value> </list> </property> </bean> <bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter"> <property name="supportedMediaTypes"> <list> <value>application/json;charset=UTF-8</value> </list> </property> </bean> </list> </property> </bean> <mvc:interceptors> <!-- 加入TraceHandlerInterceptor --> <mvc:interceptor> <mvc:mapping path="/**"/> <!-- 想加入监控的url --> <bean class="*.TraceHandlerInterceptor"> <property name="appkey" ref="octoAppKey"/> <!-- 服务标识,在octo平台申请 --> <property name="port" value="8966"/> <!-- http服务监听端口, 即jetty.port --> </bean> </mvc:interceptor> <!-- 其它配置 --> <ref bean="payTraceIdInterceptor"/> <!--入口处添加验签操作--> <mvc:interceptor> <mvc:mapping path="/**" /> <!--忽略异步通知--> <mvc:exclude-mapping path="/notify/**" /> <mvc:exclude-mapping path="/dcep/**"/> <mvc:exclude-mapping path="/dcepmock/**"/> <!--忽略对账文件下载请求--> <mvc:exclude-mapping path="/**/fileDownload" /> <mvc:exclude-mapping path="/**/monitor/alive" /> <ref bean="verifySignInterceptor"/> </mvc:interceptor> </mvc:interceptors> <mvc:annotation-driven /> <aop:aspectj-autoproxy></aop:aspectj-autoproxy>
二、关键类
1、解析处理注解@RequestMapping的类:org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping
2、org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter
浙公网安备 33010602011771号