Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 525 Vote(s) - 3.55 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to configure port for a Spring Boot application

#1
How do I configure the TCP/IP port listened on by a Spring Boot application, so it does not use the default port of 8080.
Reply

#2
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][1] "Embedded Servlet Container Support" paragraph and example there. Hope this helps.


[1]:

[To see links please register here]

Reply

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

server:
port: 9000

and of course 0 for random port.
Reply

#4
1. As everyone said, you can specify in application.properties <br>
**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<br>
**management.port = 9001** (could be any other value)

Reply

#5
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.
Reply

#6
You can add the port in below methods.

1. Run -> Configurations section

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

#7
You can set port in java code:

HashMap<String, Object> 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

Reply

#8
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
Reply

#9
In my case adding statement

server.port=${port:8081}
override the default tomcat server port.
Reply

#10
You can also use `SERVER_PORT` environment variable to configure Spring Boot port. Just set the environment variable and restart the app:

set SERVER_PORT=9999 // on windows machine
export SERVER_PORT=9999 // on linux
Please note that if you do not set those environment variables system wide, you should run the boot app on the same session.
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through