WebMvcConfigurerAdapter does not work

后端 未结 1 1732
遥遥无期
遥遥无期 2021-01-15 05:10

This is WebConfig code I am working on:

package hello.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.se         


        
相关标签:
1条回答
  • 2021-01-15 05:44

    The problem is that WebConfig is in the config package and Application is in the hello package. @SpringBootApplication on Application enables component scanning for the package in which it's declared and that package's sub-packages. In this case that means that hello is the base package for component scanning and, therefore, WebConfig in the config package is never found.

    To solve the problem I'd move WebConfig into the hello package or a sub-package, for example hello.config.

    Your latest update on GitHub changed WebConfig from extending WebMvcConfigurerAdapter to extending WebMvcConfigurationSupport. WebMvcConfigurationSupport is the class that is imported by @EnableWebMvc so annotating your class with @EnableWebMvc and extending WebMvcConfigurationSupport will be configuring things twice. You should go back to extending WebMvcConfigurerAdapter as you were before.

    0 讨论(0)
提交回复
热议问题