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/**");*/
    }

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值