Wednesday, May 24, 2017

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);
    }
}
either set server.port as system property using command line option to jvm --server.port=8090or add application.properties in /src/main/resources/ with
server.port = 8090
For random port use
server.port=0
6
When random port is used, port info can get with @Value("${local.server.port}") – azizunsal Jul 23 '15 at 12:46
14
Actually command line option is --server.port=8090 not -Dserver.port=8090. docs.spring.io/spring-boot/docs/current/reference/html/… – alpert Aug 19 '15 at 6:39
1
As a compliment to this answer: According to the spring docs there are other paths you can put application.properties on. In my case that helped a lot. – sargas Oct 2 '15 at 19:37 
8
-Dserver.port=XXXX did not work for me. I used OS environment variable mode: $ SERVER_PORT=8090 java -jar  – Soumya Kanti Oct 8 '15 at 7:38 
  
It is also worth noting that once you so this it will only matter locally. Once you deploy this application on a server `server.port = 8080 will be ignored. – Drew1208 Apr 26 '16 at 17:28
https://stackoverflow.com/questions/21083170/spring-boot-how-to-configure-port

No comments:

Portugal International Intel (Houtis hit portuguese vessel with drone )

  https://www.sandiegouniontribune.com/business/nation/story/2024-04-30/portuguese-flagged-ship-is-hit-far-in-arabian-sea-raising-concerns-o...