Get the App
SLTechnology News&Howtos  ›  Development  › 

How to set the springboot startup port in the CVM

Shulou Source: shulou.com Published: 2022-06-01 00:54:18 09月21日 Update

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!

Tags: Port server service content file learning application slogan project method computer problem run configuration one line no thing again can be passed at the same time Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB NVidia vpn Microsoft Shulou Technology