Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to set the springboot startup port

2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

In this article, the editor introduces "how to set the springboot boot port" in detail, the content is detailed, the steps are clear, and the details are handled properly. I hope this article "how to set the springboot startup port" can help you solve your doubts.

Spring boot is a good thing, it can be launched directly in the main method without a container, and there is no configuration file, which makes it easy to build the environment quickly. However, when we want to start two springboot projects at the same time, there will be a problem. It is possible that port 8080 is occupied by the first application and the second application cannot be started, so we need to modify the startup port of one of the projects.

This can be achieved by implementing the EmbeddedServletContainerCustomizer interface:

PublicclassApplicationextendsSpringBootServletInitializerimplementsEmbeddedServletContainerCustomizer {@ OverrideprotectedSpringApplicationBuilderconfigure (SpringApplicationBuilderbuilder) {returnbuilder.sources (Application.class);} publicstaticvoidmain (String [] args) {SpringApplication.run (Application.class,args);} @ Overridepublicvoidcustomize (ConfigurableEmbeddedServletContainercontainer) {container.setPort (8081);}}

PS: let's take a look at spring boot creation application port conflict 8080

If the 8080 port number on your computer is occupied by another program (such as jenkins), running lightsword will report the following error: java.net.BindException: Address already in use.Failed to start component [Connector [HTTP/1.1-8080]].

Solution: create a new file under the src- > main- > resources directory, named application.properties (this is the SpringBoot unified configuration file) and add the following line: (take a port number available on your computer, such as 9527 below, those who have seen Sing Yeh movies will know it) server.port = 9527

Just run it again.

After reading this, the article "how to set springboot Startup Port" has been introduced. If you want to master the knowledge points of this article, you still need to practice and use it yourself. If you want to know more about related articles, welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report