• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 众包
  • 赞助商
  • YouClaw
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录

无信不立

  • 博客园
  • 联系
  • 订阅
  • 管理

公告

View Post

【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>
View Code

 

二、关键类

1、解析处理注解@RequestMapping的类:org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping

2、org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter

posted on 2020-07-31 22:21  无信不立  阅读(94)  评论(0)    收藏  举报

刷新页面返回顶部
 
博客园  ©  2004-2026
浙公网安备 33010602011771号 浙ICP备2021040463号-3