有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java为什么使用WebMVCAutoConfiguration适配器类

package com.ge.hc.gsit.sbom.configuration;

import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration.WebMvcAutoConfigurationAdapter;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;

@Configuration
@EnableAutoConfiguration
@EnableWebMvc
@ComponentScan(basePackages = {"com.abc.xy.gsit.sbom.controller","com.abc.xy.gsit.sbom.exception"})
public class MvcConfig extends WebMvcAutoConfigurationAdapter{
}

我想知道WebMvcAutoConfigurationAdapter类是如何工作的

如果有任何文件,请让我知道,这将是有益的

提前谢谢


共 (1) 个答案

  1. # 1 楼答案

    WebMvcAutoConfigurationAdapter中的评论指出:

    // Defined as a nested config to ensure WebMvcConfigurerAdapter is not read when not

    // on the classpath

    WebMvcAutoConfigurationAdapter类扩展了WebMvcConfigurerAdapter并提供了WebMvcConfigurer接口方法的默认实现,这些接口方法是回调,用于定制通过@EnableWebMvc启用的基于Java的Spring MVC配置

    所以,如果你想改变一些行为,你应该扩展WebMvcConfigurerAdapter

    关于EnableAutoConfiguration和Spring Boot的更多详细信息:Understanding Spring Boot