spring boot item to set the default access path method

Application is generally by spring boot program startup, and does not require the web.xml configuration, so set the default access page may be implemented by a method, such as increasing DefaultView default class, as follows:

import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
 
/**
 * 
 *  项目默认访问路径
 */
@Configuration
public class DefaultView extends WebMvcConfigurerAdapter {
    
    @Override
    public void addViewControllers(ViewControllerRegistry reg) {
        reg.addViewController("/").setViewName("login");//默认访问页面
        reg.setOrder(Ordered.HIGHEST_PRECEDENCE);//最先执行过滤
        super.addViewControllers(reg);
    }
}

Guess you like

Origin www.cnblogs.com/kevliudm/p/11326275.html