美文网首页
springboot 中 DispatcherServlet 是

springboot 中 DispatcherServlet 是

作者: 良人与我 | 来源:发表于2019-06-21 11:47 被阅读0次

pom中引入web的start

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

在spring-boot-starter-web 的spring.provides 中:

image.png

provides: spring-webmvc,spring-web

依赖了 spring-webmvc , spring-web 包

在springboot autoconfig 中 有自动配置web 核心的 DispatcherServlet 类
DispatcherServletAutoConfiguration
在它的内部类中 初始化 DispatcherServlet


    @Configuration
    @Conditional(DefaultDispatcherServletCondition.class)
    @ConditionalOnClass(ServletRegistration.class)
    @EnableConfigurationProperties(WebMvcProperties.class)
    protected static class DispatcherServletConfiguration {

        private final WebMvcProperties webMvcProperties;

        public DispatcherServletConfiguration(WebMvcProperties webMvcProperties) {
            this.webMvcProperties = webMvcProperties;
        }

        @Bean(name = DEFAULT_DISPATCHER_SERVLET_BEAN_NAME)
        public DispatcherServlet dispatcherServlet() {
            DispatcherServlet dispatcherServlet = new DispatcherServlet();
            dispatcherServlet.setDispatchOptionsRequest(
                    this.webMvcProperties.isDispatchOptionsRequest());
            dispatcherServlet.setDispatchTraceRequest(
                    this.webMvcProperties.isDispatchTraceRequest());
            dispatcherServlet.setThrowExceptionIfNoHandlerFound(
                    this.webMvcProperties.isThrowExceptionIfNoHandlerFound());
            return dispatcherServlet;
        }

        @Bean
        @ConditionalOnBean(MultipartResolver.class)
        @ConditionalOnMissingBean(name = DispatcherServlet.MULTIPART_RESOLVER_BEAN_NAME)
        public MultipartResolver multipartResolver(MultipartResolver resolver) {
            // Detect if the user has created a MultipartResolver but named it incorrectly
            return resolver;
        }

    }

创建DispatcherServlet 的条件

1 存在 DispatcherServlet 类(web start 引入了)
2 没有 DispatcherServlet 类的bean

相关文章

网友评论

      本文标题:springboot 中 DispatcherServlet 是

      本文链接:https://www.haomeiwen.com/subject/paxyqctx.html