📘 Premium Read: Access my best content on Medium member-only articles — deep dives into Java, Spring Boot, Microservices, backend architecture, interview preparation, career advice, and industry-standard best practices.
🎓 Top 15 Udemy Courses (80-90% Discount): My Udemy Courses - Ramesh Fadatare — All my Udemy courses are real-time and project oriented courses.
▶️ Subscribe to My YouTube Channel (176K+ subscribers): Java Guides on YouTube
▶️ For AI, ChatGPT, Web, Tech, and Generative AI, subscribe to another channel: Ramesh Fadatare on YouTube
Spring Boot applications.
Let's first discuss how to change the default port for the embedded server, as we know by default, the embedded server starts on port 8080.
Video on YouTube Channel
Changing the Default Port for the Embedded server
Using application.properties File
server:
port: 8081
Programmatic Configuration
import java.util.Collections;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class Springboot2WebappJspApplication {
public static void main(String[] args) {
SpringApplication app = new SpringApplication(Springboot2WebappJspApplication.class);
app.setDefaultProperties(Collections.singletonMap("server.port", "8081"));
app.run(args);
}
}
Using Command-Line Arguments
java -jar springboot2webapp.jar --server.port=8083
java -jar -Dserver.port=8083 springboot2webapp.jar
How to Change the Default Context Path?
Using application.properties File
server.port=8080
server.servlet.context-path=/springboot2webapp
Change Context Path Programmatically
import java.util.Collections;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class Springboot2WebappJspApplication {
public static void main(String[] args) {
SpringApplication app = new SpringApplication(Springboot2WebappJspApplication.class);
app.setDefaultProperties(Collections.singletonMap("server.servlet.context-path", "/springboot2webapp"));
app.run(args);
}
}
Comments
Post a Comment
Leave Comment