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
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With