Spring boot inherits Webmvcconfigurationsupport after automatic configuration does not take effect

Source: Internet
Author: User

After the spring boot custom configuration class inherits Webmvcconfigurationsupport, it discovers the static resource path that is automatically configured (classpath:/meta/resources/,classpath:/resources/ , classpath:/static/,classpath:/public/) does not take effect.

First look at the definition of the automatic configuration class:

  

This is because there are conditional annotations on the Springboot Web Autoconfiguration class Webmvcautoconfiguration

@ConditionalOnMissingBean (Webmvcconfigurationsupport.  Class)

This annotation means that the automatic configuration class will not take effect until the Webmvcconfigurationsupport type bean is missing from the project Classpath, so the inheritance Webmvcconfigurationsupport Later, you need to rewrite the corresponding method.

If you want to use automatic configuration to take effect and rewrite some methods as you want, such as adding Viewcontroller, you can inherit the Webmvcconfigureradapter class from your own configuration class. However, after the spring5.0 version this class was discarded webmvcconfigureradapter , although it can be used, but looks bad = =.

  

This is a comment on the class, meaning that spring 5.0 uses JAVA8, and the interface in JAVA8 can have the default method, so this class is not necessary. So we just need to implement it directly in the custom configuration class.

The interface is good. As follows:

Spring boot inherits Webmvcconfigurationsupport after automatic configuration does not take effect

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.