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.
Option 1: You can use the @Value annotation and access the property in whichever Spring bean you're using @Value("${userBucket.path}") private String userBucketPath; The Externalized Configuration section of the Spring Boot docs, explains all the details that you might need. Option 2: AnotherRead more
Option 1:
You can use the @Value
annotation and access the property in whichever Spring bean you’re using
@Value("${userBucket.path}")
private String userBucketPath;
The Externalized Configuration section of the Spring Boot docs, explains all the details that you might need.
Option 2:
Another way is injecting org.springframework.core.env.Environment
to your bean.
@Autowired
private Environment env;
....
public void method() {
.....
String path = env.getProperty("userBucket.path");
.....
}
See less
Option 1: s said in docs 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 a random port use: server.port=0 Similarly add application.yml in /src/main/resources/ with: server:Read more
Option 1:
s said in docs either set
server.port
as system property using command line option to jvm-Dserver.port=8090
or addapplication.properties
in/src/main/resources/
withFor a random port use:
Similarly add
application.yml
in/src/main/resources/
with:Option 2:
You can configure the port programmatically.
For Spring Boot 2.x.x:
For older versions:
See less