第一種方式在配置文件中進行修改
1 server.port=8081 2 server.servlet.context-path=/springboot 3 server.tomcat.uri-encoding=utf-8 4 #SpringBoot自動為我們配置DispatcherServlet,默認攔截"/"(所有請求,包括靜態資源,但不攔截jsp請求,若要攔截 5 # Jsp請求,修改配置為“/*”即可) 6 spring.mvc.servlet.path=/*
第二種方式在配置類中進行修改
1 package cn.coreqi.config; 2 3 import org.springframework.boot.web.server.WebServerFactoryCustomizer; 4 import org.springframework.boot.web.servlet.server.ConfigurableServletWebServerFactory; 5 import org.springframework.context.annotation.Bean; 6 import org.springframework.context.annotation.Configuration; 7 8 @Configuration 9 public class ServletConfig { 10 11 //SpringBoot1.x使用EmbeddedServletContainerCustomizer 12 @Bean 13 public WebServerFactoryCustomizer webServerFactoryCustomizer(){ 14 return new WebServerFactoryCustomizer<ConfigurableServletWebServerFactory>(){ 15 @Override 16 public void customize(ConfigurableServletWebServerFactory factory) { 17 factory.setPort(8082); 18 } 19 }; 20 } 21 }
