SpringBoot 的默認端口號是 8080,當咱們啓動多個 springBoot 工程時,就會出現問題,報端口被佔用java
1. 能夠經過實現EmbeddedServletContainerCustomizer 接口實現:web
package com.autonavi; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.context.embedded.ConfigurableEmbeddedServletContainer; import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer; import org.springframework.boot.web.support.SpringBootServletInitializer; import org.springframework.scheduling.annotation.EnableScheduling; @SpringBootApplication @EnableScheduling public class App extends SpringBootServletInitializer implements EmbeddedServletContainerCustomizer { private static final Logger logger = LoggerFactory.getLogger(App.class); public static void main(String[] args){ SpringApplication.run(App.class, args); logger.info("start"); } @Override public void customize(ConfigurableEmbeddedServletContainer container) { // TODO Auto-generated method stub container.setPort(9188); } }
2.能夠經過application.properties 配置文件來實現spring
server.port=9188app