1. package com.shiers.config;
    2. import org.springframework.context.annotation.Configuration;
    3. import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
    4. import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
    5. /**
    6. * Demo class
    7. *
    8. * @author shierS
    9. * @date 2021/6/5
    10. */
    11. @Configuration
    12. public class WebMvcConfig implements WebMvcConfigurer {
    13. /**
    14. * 实现静态资源的注册:
    15. * Add handlers to serve static resources such as images, js, and, css files
    16. * from specific locations under web application root, the classpath, and others.
    17. * 添加处理程序来服务静态资源,如图片,js,和,css文件从特定位置下的web应用程序根,类路径,和其他。
    18. * @param registry
    19. */
    20. @Override
    21. public void addResourceHandlers(ResourceHandlerRegistry registry) {
    22. registry.addResourceHandler("/**")
    23. // 映射swagger2
    24. .addResourceLocations("classpath:/META-INF/resources/")
    25. //映射本地静态资源
    26. .addResourceLocations("file:D:\\Environment\\apache-tomcat-9.0.46\\webapps\\images\\");
    27. }
    28. }