[Solved] SpringMVC test service error

Record the errors encountered by the SSM integration:
Error message:
Warning: Exception encountered during context initialization – cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘resourceHandlerMapping’ defined in class path resource [org/springframework/web/servlet/config/annotation/DelegatingWebMvcConfiguration. class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.web.servlet.HandlerMapping]: Factory method ‘resourceHandlerMapping’ threw exception; nested exception is java.lang .IllegalStateException: No ServletContext set
June 24, 2022 4:38:47 pm org.springframework.test.context.TestContextManager prepareTestInstance
SEVERE: Caught exception while allowing TestExecutionListener [org.springframework.test.context.support.DependencyInjectionTestExecutionListener@1cab519] to prepare test instance [com.itheima.service.UserServiceTest@1a6944c]
java.lang.IllegalStateException: Failed to load ApplicationContext

Because the Spring configuration class scans the SpringMVC configuration class, it is not easy to set the filter

@Configuration
@PropertySource("jdbc.properties")
@ComponentScan(value = "com.itheima", excludeFilters = @ComponentScan.Filter(type = FilterType.ANNOTATION,value = Controller.class))
@Import({<!-- -->JdbcConfig.class, MybatisConfig.class})
public class SpringConfig {<!-- -->
}

Requires precise configuration of scan range

@Configuration
@PropertySource("jdbc.properties")
@ComponentScan({<!-- -->"com.itheima.dao", "com.itheima.service"})
@Import({<!-- -->JdbcConfig.class, MybatisConfig.class})
public class SpringConfig {<!-- -->
}