I was writing some code in Spring Boot using VS Code. Just for testing purpose to make sure everything is working fine, I was testing REST API Calls to my controller class using POSTMAN and browser. While making call to my testing method in my controller class, it gives status code “404 Not Found”. The code runs on port number 8080, my REST URL is “http://localhost:8080/tulip/testing” type=GET. Earlier I was also getting error for React project, where vs code was unable to run npx command. and the issue was with the windows defender antivirus as it was blocking the connection. but now I also have added vs code as exclusion but still it is not working. The vs code issue is also there in my company laptop, but there Spring Tool Suite works fine and Postman is able to make calls there. Any solution for this?
output in POSTMAN
{
"timestamp": "2024-05-05T17:08:33.502+00:00",
"status": 404,
"error": "Not Found",
"path": "/tulip/testing"
}
Main class
package com.ekart.tulip;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class TulipApplication {
public static void main(String[] args) {
SpringApplication.run(TulipApplication.class, args);
}
}
Controller class
package com.ekart.controller;
import org.springframework.web.bind.annotation.RestController;
import com.ekart.dto.UserDTO;
import com.ekart.service.TulipService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
@RestController
@RequestMapping("/tulip")
public class TulipController {
@Autowired
TulipService tulipService;
private static final Logger logger = LoggerFactory.getLogger(TulipController.class);
@GetMapping("/testing")
public String testing() {
return "testing";
}
@PostMapping("/register")
public ResponseEntity<String> register(@RequestBody UserDTO userDTO) {
logger.info("*************register method invoked*****************");
return ResponseEntity.ok(tulipService.register(userDTO));
}
@GetMapping("/login")
public ResponseEntity<String> login(@RequestBody UserDTO userDTO) {
return ResponseEntity.ok(null);
}
}
I am expecting Postman to be able to make REST API calls to my Spring Boot project in VS Code.
Atul Dhadwal is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.