Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Port binding for Spring RESTful Web Service

I've used the Building a RESTful Web Service tutorial to build a WebService for my purpose. It was quite easy, but now I'm struggeling to configure the port the WebService should be binded through. There is no config.xml or anything to configure in this project. Can anyone give me a hint about how to configure the WebService's port?

As these details might be helpful. I'm starting the server with the code below, containing the @EnableAutoConfiguration tag. The configuration is done by Spring Boot.

@ComponentScan
@EnableAutoConfiguration
public class ServerStarter{

public static void main(String[] args) {
        SpringApplication.run(ServerStarter.class, args);
    }
}
like image 840
Baschi Avatar asked Mar 22 '23 08:03

Baschi


2 Answers

To configure the ports you can set the server.port and management.port properties by writing the following in the "application.properties" file located under "src/main/resources":

server.port = 9000
management.port = 9001

Similarly if you need to specify the management address:

management.address = 127.0.0.1

There are more properties you can set for the server and management server. See spring-boot's documentation: http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/

like image 66
David Roberts Avatar answered Apr 26 '23 05:04

David Roberts


For a quick and dirty solution you can employ the command line option arguments (source):

 --server.port=9000 
like image 40
kolpazar Avatar answered Apr 26 '23 06:04

kolpazar