EmbeddedServletContainerCustomizer 不能import class

在学习springboot期间,遇到的问题

现在学习的springboot版本是2.0以上,可是视频中遇到的springboot是1.5.9的版本,

在学习定制嵌入式的Servlet容器相关的规则遇到的问题"EmbeddedServletContainerCustomizer"类不能导入,是因为在springboot2.0以后就不支持这个类了,改为"WebServerFactoryCustomizer"类,下面是运用:

package com.java.spring.springbootwebdemo.config;

//import org.springframework.context.annotation.Bean;
import com.java.spring.springbootwebdemo.component.MyLocaleResolver;
import com.java.spring.springbootwebdemo.component.loginHandlerInterceptor;
import org.springframework.boot.web.server.ConfigurableWebServerFactory;
import org.springframework.boot.web.server.WebServerFactoryCustomizer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.LocaleResolver;
import org.springframework.web.servlet.config.annotation.*;
//import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

@Configuration
public class MyMvcConfig implements WebMvcConfigurer{

    //定制嵌入式Servlet容器相关的规则;
    @Bean
    public WebServerFactoryCustomizer<ConfigurableWebServerFactory> webServerFactoryCustomizer(){
        return new WebServerFactoryCustomizer<ConfigurableWebServerFactory>() {
            @Override
            public void customize(ConfigurableWebServerFactory factory) {
                factory.setPort(8082);
            }
        };
    }
    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        //super.addViewControllers(registry);
        //当浏览器发送ycd请求,就会直接映射到success页面
       // registry.addViewController("ycd").setViewName("success");
        registry.addViewController("/").setViewName("login");
        registry.addViewController("/login.html").setViewName("login");
        registry.addViewController("/dashboard.html").setViewName("dashboard");
    }
    //注册拦截器
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
         /* registry.addInterceptor(new loginHandlerInterceptor()).addPathPatterns("/**")
                        .excludePathPatterns("/login.html","/","/user/login","/asserts/**","/webjars/bootstrap/**");*/
    }

}

©️2020 CSDN 皮肤主题: 创作都市 设计师:CSDN官方博客 返回首页