@EnableConfigurationProperties注解的作用:让使用@ConfigurationProperties注解的类生效,并将该类注入到IOC容器中。
@ConfigurationProperties的作用:将配置文件中的相关属性与Java Bean进行动态绑定
// 注解作用:使WebMvcProperties、ResourceProperties、ResourceProperties上标注的@ConfigurationProperties注解生效,并将其注入到IOC容器中
@EnableConfigurationProperties({ WebMvcProperties.class,
org.springframework.boot.autoconfigure.web.ResourceProperties.class, WebProperties.class })
public static class WebMvcAutoConfigurationAdapter implements WebMvcConfigurer {
// 使用@EnableConfigurationProperties注解之后,就不需要加@Component注解了
@ConfigurationProperties(prefix = "spring.mvc")
public class WebMvcProperties {