springboot configuration issues on webmvc record springboot configure a static resource access path

In the previous article ( springboot configure a static resource access path ) in said, springboot default load static resources place under static file in the resources directory folder, other than under the resources directory was static folders can be accessed in resources create a directory resources folders, public folders, META-INF / resources folder can be accessed by all to, but we recommend using static springboot default folder, but the priority is to find the META-INF / resources "public "resources" static.

When we want to modify the default static resources springboot load path, we can directly set directly in the configuration file properties, yml in, or find a configuration class (using @configuration annotated classes) so that it inherits org.springframework.web.servlet .config.annotation.WebMvcConfigurerAdapter or org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport and rewrite addResourceHandlers (ResourceHandlerRegistry registry) method, which is implemented in the air and WebMvcConfigurationSupport in WebMvcConfigurerAdapter.

Here, it is recommended springboot 1.x versions use WebMvcConfigurerAdapter this class, 2.x versions achieve WebMvcConfigurer interface is not recommended WebMvcConfigurationSupport and @EnableWebMvc comment. Because springboot default configuration will give us add a class WebMvcAutoConfiguration, but load the configuration class is conditional ( @ConditionalOnMissingBean (WebMvcConfigurationSupport.class) ), only the lack of WebMvcConfigurationSupport class configuration takes effect when we use inheritance WebMvcConfigurationSupport or @EnableWebMvc comment (this comment will import DelegatingWebMvcConfiguration, this class inherits from WebMvcConfigurationSupport

Time), springboot will not help us load the configuration WebMvcAutoConfiguration this category, and this time we need to make some webmvc configuration. And if we compare the pit WebMvcConfigurationSupport use inheritance in this way, can not be used more than once, that if we have two or more configuration class inherited WebMvcConfigurationSupport, there will only be a take effect; when we have to configure that the use of @EnableWebMvc when the class inherits WebMvcConfigurationSupport, our configuration will take effect in the class.

@ EnableWebMvc, WebMvcConfigurationSupport, WebMvcConfigurerAdapter use three effects:

  1. Use WebMvcConfigurerAdapter ===== "All the entry into force
  2. Use WebMvcConfigurationSupport (more) ==== "a certain force, the other does not take effect
  3. Use WebMvcConfigurerAdapter + WebMvcConfigurationSupport ==== "WebMvcConfigurationSupport into force
  4. Use @ EnableWebMvc + WebMvcConfigurationSupport ==== "WebMvcConfigurationSupport into force
  5. Use @ EnableWebMvc + WebMvcConfigurerAdapter ==== "WebMvcConfigurerAdapter not take effect

Guess you like

Origin www.cnblogs.com/zzw-blog/p/11457417.html
Recommended