什麼是Servlet? Servlet是使用Java語言編寫的運行在伺服器端的程式。狹義的Servlet是指Java語言實現的一個介面,廣義的Servlet是指任何實現了這個Servlet介面的類,一般情況下,人們將Servlet理解為後者。Servlet 主要用於處理客戶端傳來的 HTTP 請求, ...
什麼是Servlet?
- Servlet是使用Java語言編寫的運行在伺服器端的程式。狹義的Servlet是指Java語言實現的一個介面,廣義的Servlet是指任何實現了這個Servlet介面的類,一般情況下,人們將Servlet理解為後者。Servlet 主要用於處理客戶端傳來的 HTTP 請求,並返回一個響應,它能夠處理的請求有doGet()和doPost()等方法
- Servlet由Servlet容器提供,所謂的Servlet容器是指提供了Servlet 功能的伺服器(本書中指Tomcat),Servlet容器將Servlet動態地載入到伺服器上。與HTTP 協議相關的Servlet使用HTTP請求和HTTP響應與客戶端進行交互。因此,Servlet容器支持所有HTTP協議的請求和響應。Servlet應用程式的體繫結構如圖所示。<<javaWeb程式設計教程>>
什麼是SpringMVC?
- Spring MVC一開始就定位於一個較為鬆散的組合,展示給用戶的視圖(View)、控制器返回的數據模型(Model)、定位視圖的視圖解析器(ViewResolver)和處理適配器(HandlerAdapter)等內容都是獨立的。換句話說,通過Spring MVC很容易把後臺的數據轉換為各種類型的數據,以滿足移動互聯網數據多樣化的要求。例如,Spring MVC可以十分方便地轉換為目前最常用的JSON數據集,也可以轉換為PDF、Excel和XML等。加之Spring MVC是基於Spring基礎框架派生出來的Web框架,所以它天然就可以十分方便地整合到Spring框架中,而Spring整合Struts2還是比較繁複的.
- mvc架構設計:處理請求先到達控制器(Controller),控制器的作用是進行請求分發,這樣它會根據請求的內容去訪問模型層(Model);在現今互聯網系統中,數據主要從資料庫和NoSQL中來,而且對於資料庫而言往往還存在事務的機制,為了適應這樣的變化,設計者會把模型層再細分為兩層,即服務層(Service)和數據訪問層(DAO);當控制器獲取到由模型層返回的數據後,就將數據渲染到視圖中,這樣就能夠展現給用戶了
-
圖取自於<<深入淺出springboot2.x>>書籍
思考和疑問
早些年的時候,使用servlet開發web程式, 一般都是繼承HttpServlet介面,請求訪問時直接根據類名調用.但這樣寫的結果是,一個類只能處理一個請求.項目結構大概長這樣
使用SpringMVC框架後,只需要配置簡單的@RequestMapping("")就可以找到對應的方法,原來的servlet呢? 對springMVC的瞭解還是不夠詳細,所以
繼續探討以下幾個問題
1.SpringMVC如何代替Servlet?
可以看到DispatcherServlet繼承自HttpServlet, 前端控制器其實就相當於一個Servlet.
2. SpringMVC的工作流程?
圖取自於<<深入淺出springboot2.x>>書籍
基於springboot開發使得SpringMVC的使用更為簡便,可以通過Spring Boot的配置來定製這些組件的初始化
-
/* * Copyright 2002-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.springframework.web.servlet; import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Enumeration; import java.util.HashMap; import java.util.HashSet; import java.util.LinkedList; import java.util.List; import java.util.Locale; import java.util.Map; import java.util.Properties; import java.util.Set; import java.util.stream.Collectors; import javax.servlet.DispatcherType; import javax.servlet.ServletContext; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.beans.factory.BeanFactoryUtils; import org.springframework.beans.factory.BeanInitializationException; import org.springframework.beans.factory.NoSuchBeanDefinitionException; import org.springframework.context.ApplicationContext; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.i18n.LocaleContext; import org.springframework.core.annotation.AnnotationAwareOrderComparator; import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.support.PropertiesLoaderUtils; import org.springframework.core.log.LogFormatUtils; import org.springframework.http.server.ServletServerHttpRequest; import org.springframework.lang.Nullable; import org.springframework.ui.context.ThemeSource; import org.springframework.util.ClassUtils; import org.springframework.util.StringUtils; import org.springframework.web.context.WebApplicationContext; import org.springframework.web.context.request.ServletWebRequest; import org.springframework.web.context.request.async.WebAsyncManager; import org.springframework.web.context.request.async.WebAsyncUtils; import org.springframework.web.multipart.MultipartException; import org.springframework.web.multipart.MultipartHttpServletRequest; import org.springframework.web.multipart.MultipartResolver; import org.springframework.web.util.NestedServletException; import org.springframework.web.util.WebUtils; /** * Central dispatcher for HTTP request handlers/controllers, e.g. for web UI controllers * or HTTP-based remote service exporters. Dispatches to registered handlers for processing * a web request, providing convenient mapping and exception handling facilities. * * <p>This servlet is very flexible: It can be used with just about any workflow, with the * installation of the appropriate adapter classes. It offers the following functionality * that distinguishes it from other request-driven web MVC frameworks: * * <ul> * <li>It is based around a JavaBeans configuration mechanism. * * <li>It can use any {@link HandlerMapping} implementation - pre-built or provided as part * of an application - to control the routing of requests to handler objects. Default is * {@link org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping} and * {@link org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping}. * HandlerMapping objects can be defined as beans in the servlet's application context, * implementing the HandlerMapping interface, overriding the default HandlerMapping if * present. HandlerMappings can be given any bean name (they are tested by type). * * <li>It can use any {@link HandlerAdapter}; this allows for using any handler interface. * Default adapters are {@link org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter}, * {@link org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter}, for Spring's * {@link org.springframework.web.HttpRequestHandler} and * {@link org.springframework.web.servlet.mvc.Controller} interfaces, respectively. A default * {@link org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter} * will be registered as well. HandlerAdapter objects can be added as beans in the * application context, overriding the default HandlerAdapters. Like HandlerMappings, * HandlerAdapters can be given any bean name (they are tested by type). * * <li>The dispatcher's exception resolution strategy can be specified via a * {@link HandlerExceptionResolver}, for example mapping certain exceptions to error pages. * Default are * {@link org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver}, * {@link org.springframework.web.servlet.mvc.annotation.ResponseStatusExceptionResolver}, and * {@link org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver}. * These HandlerExceptionResolvers can be overridden through the application context. * HandlerExceptionResolver can be given any bean name (they are tested by type). * * <li>Its view resolution strategy can be specified via a {@link ViewResolver} * implementation, resolving symbolic view names into View objects. Default is * {@link org.springframework.web.servlet.view.InternalResourceViewResolver}. * ViewResolver objects can be added as beans in the application context, overriding the * default ViewResolver. ViewResolvers can be given any bean name (they are tested by type). * * <li>If a {@link View} or view name is not supplied by the user, then the configured * {@link RequestToViewNameTranslator} will translate the current request into a view name. * The corresponding bean name is "viewNameTranslator"; the default is * {@link org.springframework.web.servlet.view.DefaultRequestToViewNameTranslator}. * * <li>The dispatcher's strategy for resolving multipart requests is determined by a * {@link org.springframework.web.multipart.MultipartResolver} implementation. * Implementations for Apache Commons FileUpload and Servlet 3 are included; the typical * choice is {@link org.springframework.web.multipart.commons.CommonsMultipartResolver}. * The MultipartResolver bean name is "multipartResolver"; default is none. * * <li>Its locale resolution strategy is determined by a {@link LocaleResolver}. * Out-of-the-box implementations work via HTTP accept header, cookie, or session. * The LocaleResolver bean name is "localeResolver"; default is * {@link org.springframework.web.servlet.i18n.AcceptHeaderLocaleResolver}. * * <li>Its theme resolution strategy is determined by a {@link ThemeResolver}. * Implementations for a fixed theme and for cookie and session storage are included. * The ThemeResolver bean name is "themeResolver"; default is * {@link org.springframework.web.servlet.theme.FixedThemeResolver}. * </ul> * * <p><b>NOTE: The {@code @RequestMapping} annotation will only be processed if a * corresponding {@code HandlerMapping} (for type-level annotations) and/or * {@code HandlerAdapter} (for method-level annotations) is present in the dispatcher.</b> * This is the case by default. However, if you are defining custom {@code HandlerMappings} * or {@code HandlerAdapters}, then you need to make sure that a corresponding custom * {@code RequestMappingHandlerMapping} and/or {@code RequestMappingHandlerAdapter} * is defined as well - provided that you intend to use {@code @RequestMapping}. * * <p><b>A web application can define any number of DispatcherServlets.</b> * Each servlet will operate in its own namespace, loading its own application context * with mappings, handlers, etc. Only the root application context as loaded by * {@link org.springframework.web.context.ContextLoaderListener}, if any, will be shared. * * <p>As of Spring 3.1, {@code DispatcherServlet} may now be injected with a web * application context, rather than creating its own internally. This is useful in Servlet * 3.0+ environments, which support programmatic registration of servlet instances. * See the {@link #DispatcherServlet(WebApplicationContext)} javadoc for details. * * @author Rod Johnson * @author Juergen Hoeller * @author Rob Harrop * @author Chris Beams * @author Rossen Stoyanchev * @see org.springframework.web.HttpRequestHandler * @see org.springframework.web.servlet.mvc.Controller * @see org.springframework.web.context.ContextLoaderListener */ @SuppressWarnings("serial") public class DispatcherServlet extends FrameworkServlet { /** Well-known name for the MultipartResolver object in the bean factory for this namespace. */ public static final String MULTIPART_RESOLVER_BEAN_NAME = "multipartResolver"; /** Well-known name for the LocaleResolver object in the bean factory for this namespace. */ public static final String LOCALE_RESOLVER_BEAN_NAME = "localeResolver"; /** Well-known name for the ThemeResolver object in the bean factory for this namespace. */ public static final String THEME_RESOLVER_BEAN_NAME = "themeResolver"; /** * Well-known name for the HandlerMapping object in the bean factory for this namespace. * Only used when "detectAllHandlerMappings" is turned off. * @see #setDetectAllHandlerMappings */ public static final String HANDLER_MAPPING_BEAN_NAME = "handlerMapping"; /** * Well-known name for the HandlerAdapter object in the bean factory for this namespace. * Only used when "detectAllHandlerAdapters" is turned off. * @see #setDetectAllHandlerAdapters */ public static final String HANDLER_ADAPTER_BEAN_NAME = "handlerAdapter"; /** * Well-known name for the HandlerExceptionResolver object in the bean factory for this namespace. * Only used when "detectAllHandlerExceptionResolvers" is turned off. * @see #setDetectAllHandlerExceptionResolvers */ public static final String HANDLER_EXCEPTION_RESOLVER_BEAN_NAME = "handlerExceptionResolver"; /** * Well-known name for the RequestToViewNameTranslator object in the bean factory for this namespace. */ public static final String REQUEST_TO_VIEW_NAME_TRANSLATOR_BEAN_NAME = "viewNameTranslator"; /** * Well-known name for the ViewResolver object in the bean factory for this namespace. * Only used when "detectAllViewResolvers" is turned off. * @see #setDetectAllViewResolvers */ public static final String VIEW_RESOLVER_BEAN_NAME = "viewResolver"; /** * Well-known name for the FlashMapManager object in the bean factory for this namespace. */ public static final String FLASH_MAP_MANAGER_BEAN_NAME = "flashMapManager"; /** * Request attribute to hold the current web application context. * Otherwise only the global web app context is obtainable by tags etc. * @see org.springframework.web.servlet.support.RequestContextUtils#findWebApplicationContext */ public static final String WEB_APPLICATION_CONTEXT_ATTRIBUTE = DispatcherServlet.class.getName() + ".CONTEXT"; /** * Request attribute to hold the current LocaleResolver, retrievable by views. * @see org.springframework.web.servlet.support.RequestContextUtils#getLocaleResolver */ public static final String LOCALE_RESOLVER_ATTRIBUTE = DispatcherServlet.class.getName() + ".LOCALE_RESOLVER"; /** * Request attribute to hold the current ThemeResolver, retrievable by views. * @see org.springframework.web.servlet.support.RequestContextUtils#getThemeResolver */ public static final String THEME_RESOLVER_ATTRIBUTE = DispatcherServlet.class.getName() + ".THEME_RESOLVER"; /** * Request attribute to hold the current ThemeSource, retrievable by views. * @see org.springframework.web.servlet.support.RequestContextUtils#getThemeSource */ public static final String THEME_SOURCE_ATTRIBUTE = DispatcherServlet.class.getName() + ".THEME_SOURCE"; /** * Name of request attribute that holds a read-only {@code Map<String,?>} * with "input" flash attributes saved by a previous request, if any. * @see org.springframework.web.servlet.support.RequestContextUtils#getInputFlashMap(HttpServletRequest) */ public static final String INPUT_FLASH_MAP_ATTRIBUTE = DispatcherServlet.class.getName() + ".INPUT_FLASH_MAP"; /** * Name of request attribute that holds the "output" {@link FlashMap} with * attributes to save for a subsequent request. * @see org.springframework.web.servlet.support.RequestContextUtils#getOutputFlashMap(HttpServletRequest) */ public static final String OUTPUT_FLASH_MAP_ATTRIBUTE = DispatcherServlet.class.getName() + ".OUTPUT_FLASH_MAP"; /** * Name of request attribute that holds the {@link FlashMapManager}. * @see org.springframework.web.servlet.support.RequestContextUtils#getFlashMapManager(HttpServletRequest) */ public static final String FLASH_MAP_MANAGER_ATTRIBUTE = DispatcherServlet.class.getName() + ".FLASH_MAP_MANAGER"; /** * Name of request attribute that exposes an Exception resolved with a * {@link HandlerExceptionResolver} but where no view was rendered * (e.g. setting the status code). */ public static final String EXCEPTION_ATTRIBUTE = DispatcherServlet.class.getName() + ".EXCEPTION"; /** Log category to use when no mapped handler is found for a request. */ public static final String PAGE_NOT_FOUND_LOG_CATEGORY = "org.springframework.web.servlet.PageNotFound"; /** * Name of the class path resource (relative to the DispatcherServlet class) * that defines DispatcherServlet's default strategy names. */ private static final String DEFAULT_STRATEGIES_PATH = "DispatcherServlet.properties"; /** * Common prefix that DispatcherServlet's default strategy attributes start with. */ private static final String DEFAULT_STRATEGIES_PREFIX = "org.springframework.web.servlet"; /** Additional logger to use when no mapped handler is found for a request. */ protected static final Log pageNotFoundLogger = LogFactory.getLog(PAGE_NOT_FOUND_LOG_CATEGORY); private static final Properties defaultStrategies; static { // Load default strategy implementations from properties file. // This is currently strictly internal and not meant to be customized // by application developers. try { ClassPathResource resource = new ClassPathResource(DEFAULT_STRATEGIES_PATH, DispatcherServlet.class); defaultStrategies = PropertiesLoaderUtils.loadProperties(resource); } catch (IOException ex) { throw new IllegalStateException("Could not load '" + DEFAULT_STRATEGIES_PATH + "': " + ex.getMessage()); } } /** Detect all HandlerMappings or just expect "handlerMapping" bean?. */ private boolean detectAllHandlerMappings = true; /** Detect all HandlerAdapters or just expect "handlerAdapter" bean?. */ private boolean detectAllHandlerAdapters = true; /** Detect all HandlerExceptionResolvers or just expect "handlerExceptionResolver" bean?. */ private boolean detectAllHandlerExceptionResolvers = true; /** Detect all ViewResolvers or just expect "viewResolver" bean?. */ private boolean detectAllViewResolvers = true; /** Throw a NoHandlerFoundException if no Handler was found to process this request? *.*/ private boolean throwExceptionIfNoHandlerFound = false; /** Perform cleanup of request attributes after include request?. */ private boolean cleanupAfterInclude = true; /** MultipartResolver used by this servlet. */ @Nullable private MultipartResolver multipartResolver; /** LocaleResolver used by this servlet. */ @Nullable private LocaleResolver localeResolver; /** ThemeResolver used by this servlet. */ @Nullable private ThemeResolver themeResolver; /** List of HandlerMappings used by this servlet. */ @Nullable private List<HandlerMapping> handlerMappings; /** List of HandlerAdapters used by this servlet. */ @Nullable private List<HandlerAdapter> handlerAdapters; /** List of HandlerExceptionResolvers used by this servlet. */ @Nullable private List<HandlerExceptionResolver> handlerExceptionResolvers; /** RequestToViewNameTranslator used by this servlet. */ @Nullable private RequestToViewNameTranslator viewNameTranslator; /** FlashMapManager used by this servlet. */ @Nullable private FlashMapManager flashMapManager; /** List of ViewResolvers used by this servlet. */ @Nullable private List<ViewResolver> viewResolvers; /** * Create a new {@code DispatcherServlet} that will create its own internal web * application context based on defaults and values provided through servlet * init-params. Typically used in Servlet 2.5 or earlier environments, where the only * option for servlet registration is through {@code web.xml} which requires the use * of a no-arg constructor. * <p>Calling {@link #setContextConfigLocation} (init-param 'contextConfigLocation') * will dictate which XML files will be loaded by the * {@linkplain #DEFAULT_CONTEXT_CLASS default XmlWebApplicationContext} * <p>Calling {@link #setContextClass} (init-param 'contextClass') overrides the * default {@code XmlWebApplicationContext} and allows for specifying an alternative class, * such as {@code AnnotationConfigWebApplicationContext}. * <p>Calling {@link #setContextInitializerClasses} (init-param 'contextInitializerClasses') * indicates which {@code ApplicationContextInitializer} classes should be used to * further configure the internal application context prior to refresh(). * @see #DispatcherServlet(WebApplicationContext) */ public DispatcherServlet() { super(); setDispatchOptionsRequest(true); } /** * Create a new {@code DispatcherServlet} with the given web application context. This * constructor is useful in Servlet 3.0+ environments where instance-based registration * of servlets is possible through the {@link ServletContext#addServlet} API. * <p>Using this constructor indicates that the following properties / init-params * will be ignored: * <ul> * <li>{@link #setContextClass(Class)} / 'contextClass'</li> * <li>{@link #setContextConfigLocation(String)} / 'contextConfigLocation'</li> * <li>{@link #setContextAttribute(String)} / 'contextAttribute'</li> * <li>{@link #setNamespace(String)} / 'namespace'</li> * </ul> * <p>The given web application context may or may not yet be {@linkplain * ConfigurableApplicationContext#refresh() refreshed}. If it has <strong>not</strong> * already been refreshed (the recommended approach), then the following will occur: * <ul> * <li>If the given context does not already have a {@linkplain * ConfigurableApplicationContext#setParent parent}, the root application context * will be set as the parent.</li> * <li>If the given context has not already been assigned an {@linkplain * ConfigurableApplicationContext#setId id}, one will be assigned to it</li> * <li>{@code ServletContext} and {@code ServletConfig} objects will be delegated to * the application context</li> * <li>{@link #postProcessWebApplicationContext} will be called</li> * <li>Any {@code ApplicationContextInitializer}s specified through the * "contextInitializerClasses" init-param or through the {@link * #setContextInitializers} property will be applied.</li> * <li>{@link ConfigurableApplicationContext#refresh refresh()} will be called if the * context implements {@link ConfigurableApplicationContext}</li> * </ul> * If the context has already been refreshed, none of the above will occur, under the * assumption that the user has performed these actions (or not) per their specific * needs. * <p>See {@link org.springframework.web.WebApplicationInitializer} for usage examples. * @param webApplicationContext the context to use * @see #initWebApplicationContext * @see #configureAndRefreshWebApplicationContext * @see org.springframework.web.WebApplicationInitializer */ public DispatcherServlet(WebApplicationContext webApplicationContext) { super(webApplicationContext); setDispatchOptionsRequest(true); } /** * Set whether to detect all HandlerMapping beans in this servlet's context. Otherwise, * just a single bean with name "handlerMapping" will be expected. * <p>Default is "true". Turn this off if you want this servlet to use a single * HandlerMapping, despite multiple HandlerMapping beans being defined in the context. */ public void setDetectAllHandlerMappings(boolean detectAllHandlerMappings) { this.detectAllHandlerMappings = detectAllHandlerMappings; } /** * Set whether to detect all HandlerAdapter beans in this servlet's context. Otherwise, * just a single bean with name "handlerAdapter" will be expected. * <p>Default is "true". Turn this off if you want this servlet to use a single * HandlerAdapter, despite multiple HandlerAdapter beans being defined in the context. */ public void setDetectAllHandlerAdapters(boolean detectAllHandlerAdapters) { this.detectAllHandlerAdapters = detectAllHandlerAdapters; } /** * Set whether to detect all HandlerExceptionResolver beans in this servlet's context. Otherwise, * just a single bean with name "handlerExceptionResolver" will be expected. * <p>Default is "true". Turn this off if you want this servlet to use a single * HandlerExceptionResolver, despite multiple HandlerExceptionResolver beans being defined in the context. */ public void setDetectAllHandlerExceptionResolvers(boolean detectAllHandlerExceptionResolvers) { this.detectAllHandlerExceptionResolvers = detectAllHandlerExceptionResolvers; } /** * Set whether to detect all ViewResolver beans in this servlet's context. Otherwise, * just a single bean with name "viewResolver" will be expected. * <p>Default is "true". Turn this off if you want this servlet to use a single * ViewResolver, despite multiple ViewResolver beans being defined in the context. */ public void setDetectAllViewResolvers(boolean detectAllViewResolvers) { this.detectAllViewResolvers = detectAllViewResolvers; } /** * Set whether to throw a NoHandlerFoundException when no Handler was found for this request. * This exception can then be caught with a HandlerExceptionResolver or an * {@code @ExceptionHandler} controller method. * <p>Note that if {@link org.springframework.web.servlet.resource.DefaultServletHttpRequestHandler} * is used, then requests will always be forwarded to the default servlet and a * NoHandlerFoundException would never be thrown in that case. * <p>Default is "false", meaning the DispatcherServlet sends a NOT_FOUND error through the * Servlet response. * @since 4.0 */ public void setThrowExceptionIfNoHandlerFound(boolean throwExceptionIfNoHandlerFound) { this.throwExceptionIfNoHandlerFound = throwExceptionIfNoHandlerFound; } /** * Set whether to perform cleanup of request attributes after an include request, that is, * whether to reset the original state of all request attributes after the DispatcherServlet * has processed within an include request. Otherwise, just the DispatcherServlet's own * request attributes will be reset, but not model attributes for JSPs or special attributes * set by views (for example, JSTL's). * <p>Default is "true", which is strongly recommended. Views should not rely on request attributes * having been set by (dynamic) includes. This allows JSP views rendered by an included controller * to use any model attributes, even with the same names as in the main JSP, without causing side * effects. Only turn this off for special needs, for example to deliberately allow main JSPs to * access attributes from JSP views rendered by an included controller. */ public void setCleanupAfterInclude(boolean cleanupAfterInclude) { this.cleanupAfterInclude = cleanupAfterInclude; } /** * This implementation calls {@link #initStrategies}. */ @Override protected void onRefresh(ApplicationContext context) { initStrategies(context); } /** * Initialize the strategy objects that this servlet uses. * <p>May be overridden in subclasses in order to initialize further strategy objects. */ protected void initStrategies(ApplicationContext context) { initMultipartResolver(context); initLocaleResolver(context); initThemeResolver(context); initHandlerMappings(context); initHandlerAdapters(context); initHandlerExceptionResolvers(context); initRequestToViewNameTranslator(context); initViewResolvers(context); initFlashMapManager(context); } /** * Initialize the MultipartResolver used by this class. * <p>If no bean is defined with the given name in the BeanFactory for this namespace, * no multipart handling is provided. */ private void initMultipartResolver(ApplicationContext context) { try { this.multipartResolver = context.getBean(MULTIPART_RESOLVER_BEAN_NAME, MultipartResolver.class); if (logger.isTraceEnabled()) { logger.trace("Detected " + this.multipartResolver); } else if (logger.isDebugEnabled()) { logger.debug("Detected " + this.multipartResolver.getClass().getSimpleName()); } } catch (NoSuchBeanDefinitionException ex) { // Default is no multipart resolver. this.multipartResolver = null; if (logger.isTraceEnabled()) { logger.trace("No MultipartResolver '" + MULTIPART_RESOLVER_BEAN_NAME + "' declared"); } } } /** * Initialize the LocaleResolver used by this class. * <p>If no bean is defined with the given name in the BeanFactory for this namespace, * we default to AcceptHeaderLocaleResolver. */ private void initLocaleResolver(ApplicationContext context) { try { this.localeResolver = context.getBean(LOCALE_RESOLVER_BEAN_NAME, LocaleResolver.class); if (logger.isTraceEnabled()) { logger.trace("Detected " + this.localeResolver); } else if (logger.isDebugEnabled()) { logger.debug("Detected " + this.localeResolver.getClass().getSimpleName()); } } catch (NoSuchBeanDefinitionException ex) { // We need to use the default.