How to set the springboot startup port
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.