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:

Sabotage RFID NFC machinery

  https://www.grandslipring.com/inductive-coupling/ https://physics.stackexchange.com/questions/17200/can-magnetic-fields-be-redirected-and-...