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 in the CVM

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

Share

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

This article mainly explains "how to set the springboot startup port in the CVM". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to set the springboot startup port in the CVM".

CVM: spring boot is a good thing, it can be launched directly in the main method without a container, and no configuration file is needed, so it is convenient 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:

Public class Application extends SpringBootServletInitializer implements EmbeddedServletContainerCustomizer {

@ Override

Protected SpringApplicationBuilder configure (SpringApplicationBuilder builder) {

Return builder.sources (Application.class)

}

Public static void main (String [] args) {

SpringApplication.run (Application.class, args)

}

@ Override

Public void customize (ConfigurableEmbeddedServletContainer container) {

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.

Thank you for your reading. The above is the content of "how to set the springboot startup port in the CVM". After the study of this article, I believe you have a deeper understanding of how to set the springboot startup port in the CVM, and the specific usage needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

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