I'm programming an Api REST in Spring boot and I have an error from Postman while I'm trying to fetch the users, i literally went out of ideas:
{
"timestamp": "2023-03-06T03:46:26.764+00:00",
"status": 404,
"error": "Not Found",
"message": "No message available",
"path": "/api/usuarios/allUsers"
}
and this is my project's code base:
@RestController
@RequestMapping("/api/users")
public class UserController {
@Autowired
private UsuariosRepository repo;
@GetMapping("/allUser")
@ResponseBody
public List<Usuarios> fetchUsers() {
return repo.findAll();
}
}
this is my main class where I've already checked:
@SpringBootApplication
public class FitnessApplication {
public static void main(String[] args) {
SpringApplication.run(FitnessApplication.class, args);
}
}
this is the repository where I've already checked too:
@Repository
public interface UsuariosRepository extends JpaRepository<Usuarios,Long> {
}
and this is my Entity class:
@Entity
@Table(name = "usuarios")
public class Usuarios {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String nombre;
private String apellido_paterno;
private String apellido_materno;
private String correo;
private String telefono;
private String password;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getNombre() {
return nombre;
}
public void setNombre(String nombre) {
this.nombre = nombre;
}
public String getApellido_paterno() {
return apellido_paterno;
}
public void setApellido_paterno(String apellido_paterno) {
this.apellido_paterno = apellido_paterno;
}
public String getApellido_materno() {
return apellido_materno;
}
public void setApellido_materno(String apellido_materno) {
this.apellido_materno = apellido_materno;
}
public String getCorreo() {
return correo;
}
public void setCorreo(String correo) {
this.correo = correo;
}
public String getTelefono() {
return telefono;
}
public void setTelefono(String telefono) {
this.telefono = telefono;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}
I went out of ideas, help!
You have a typo in the url you typed "/api/usuarios/allUsers"
it should be "https://localhost:\<application-port>/api/users/allUser"
.
As @Bejond mentioned 404 means no resource found . Usually errors in the 400s indicates a client-side issue.