當前位置:
首頁 >
前端技术
> javascript
>内容正文
javascript
SpringBoot 修改tomcat端口
生活随笔
收集整理的這篇文章主要介紹了
SpringBoot 修改tomcat端口
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
參考自:https://blog.csdn.net/wsh900221/article/details/80521313
?
在spring boot的web 工程中,可以使用內置的web container、有時需要修改服務端口。
方法一:通過配置類和@Configuration注解來完成
import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.context.embedded.EmbeddedServletContainerFactory; import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @Configuration public class MyConfiguration { @Value("${tomcatport:8090}") private int port; @Bean public EmbeddedServletContainerFactory servletContainer(){ return new TomcatEmbeddedServletContainerFactory(this.port); } }使用@Value注解,為tomcatport賦予8090的端口。
可以進入TomcatEmbeddedServletContainerFactory類查看實現的處理。
方法二:在應用的application.properties或者yml配置文件中,添加配置項
#指定web 的 contex path server.contextPath=/myapp #指定服務端口 server.port=8080總結
以上是生活随笔為你收集整理的SpringBoot 修改tomcat端口的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 深度步态识别综述(一)
- 下一篇: 【Spring】Spring的IOC依赖