Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Context path is not working for SpringBoot 3

I gave below property in the application.properties file

server.servlet.context-path=/api

But when I am hitting the endpoint using Postman, I am getting endpoint not found error. I am new to SpringBoot so please help me. I am using Java 17 and SpringBoot 3.0.8

like image 351
Tushar Agarwal Avatar asked Nov 06 '25 21:11

Tushar Agarwal


2 Answers

It seems that issue was with the dependency. I was importing org.springframework.boot:spring-boot-starter-webflux earlier. Netty is the default embedded container for webflux and it seems it doesn't support servlet context path. Once I replaced it with org.springframework.boot:spring-boot-starter-web, it uses Tomcat as default embedded server which perfectly supports servlet context-path.

org.springframework.boot:spring-boot-starter-webflux builds the application using Spring Webflux whereas org.springframework.boot:spring-boot-starter-web builds the application using Spring MVC.

like image 130
Tushar Agarwal Avatar answered Nov 09 '25 10:11

Tushar Agarwal


Use this property server.servlet.contextPath=/api. In startup logs you will see the following logger to confirm that contextPath is set Tomcat started on port(s): 8080 (http) with context path /api

like image 42
Jay Yadav Avatar answered Nov 09 '25 10:11

Jay Yadav