Blog coding and discussion of coding about JavaScript, PHP, CGI, general web building etc.

Friday, April 15, 2016

Spring Boot - how to configure port

Spring Boot - how to configure port


Looking for way how to configure port in Spring boot app:

@Controller  @EnableAutoConfiguration  public class SampleController {        @RequestMapping("/")      @ResponseBody      String home() {          return "Hello World!";      }        public static void main(String[] args) throws Exception {          SpringApplication.run(SampleController.class, args);      }  }  

That is all sources :)

Answer by Paul Verest for Spring Boot - how to configure port


As said in docs http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#howto-change-the-http-port

either set server.port as system property using command line option to jvm -Dserver.port=8090 or add application.properties in /src/main/resources/ with

server.port = 8090  

For random port use

server.port=0  

Answer by nndru for Spring Boot - how to configure port


You can specify port by overriding EmbeddedServletContainerFactory bean within your configuration (java based or xml). There you can specify port for used embedded servlet container. Please, see Spring Boot - Core "Embedded Servlet Container Support" paragraph and example there. Hope this helps.

Answer by gatolgaj for Spring Boot - how to configure port


In case you are using application.yml add the Following lines to it

server:       port: 9000  

and of course 0 for random port.

Answer by anataliocs for Spring Boot - how to configure port


There are two main ways to change the port in the Embedded Tomcat in a Spring Boot Application.

Modify application.properties

First you can try the application.properties file in the /resources folder:

application.properties file

Modify a VM option

The second way, if you want to avoid modifying any files and checking in something that you only need on your local, you can use a vm arg:

Go to Run -> Edit Configurations -> VM options

-Dserver.port=8090  

Change port with a vm arg

Additionally, if you need more information you can view the following blog post here: Changing the port on a Spring Boot Application

Answer by Rakesh for Spring Boot - how to configure port


  1. As everyone said, you can specify in application.properties
    server.port = 9000 (could be any other value)

  2. If you are using spring actuator in your project, by default it points to
    8080, and if you want to change it, then in application.properties mention
    management.port = 9001 (could be any other value)

Answer by makerj for Spring Boot - how to configure port


also, you can configure port programmatically

@Controller  public class ServletConfig {      @Bean      public EmbeddedServletContainerCustomizer containerCustomizer() {          return (container -> {              container.setPort(8012);          });      }  }  

Answer by Adrian Cosma for Spring Boot - how to configure port


Indeed, the easiest way is to set the server.port property.

If you are using STS as IDE, from version 3.6.7 you actually have Spring Properties Editor for opening the properties file.

This editor provides autocomplete for all Spring Boot properties. If you write port and hit CTRL + SPACE, server.port will be the first option.

Answer by Karthikeyan Govindaraj for Spring Boot - how to configure port


You can add the port in below methods.

  1. Run -> Configurations section

  2. In application.xml add server.port=XXXX

Answer by ayurchuk for Spring Boot - how to configure port


You can set port in java code:

HashMap props = new HashMap<>();  props.put("server.port", 9999);    new SpringApplicationBuilder()      .sources(SampleController.class)                      .properties(props)      .run(args);  

Or in application.yml:

server:      port: 9999  

Or in application.properties:

server.port=9999  

Or as a command line parameter:

-Dserver.port=9999  

Answer by Luis Mauricio for Spring Boot - how to configure port


When you need a programatically way of doing it, you can set it during startup:

System.getProperties().put( "server.port", 80 );  SpringApplication.run(App.class, args);  

This might help for things like environment dependent port. Have a nice day

Answer by roll tide for Spring Boot - how to configure port


If you would like to do it at running it locally than use this -

mvn spring-boot:run -Drun.jvmArguments='-Dserver.port=8085'


Fatal error: Call to a member function getElementsByTagName() on a non-object in D:\XAMPP INSTALLASTION\xampp\htdocs\endunpratama9i\www-stackoverflow-info-proses.php on line 72

0 comments:

Post a Comment

Popular Posts

Powered by Blogger.