I'm making a RestApi in Java Spring(Gradle). When compile the code, and try it in Postman it returns with 404. I don't know why, and it is very annoying.
package arma.Arma.RestController;import arma.Arma.Service.UserService;import arma.Arma.doman.User;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.http.MediaType;import org.springframework.web.bind.annotation.*;import java.util.List;@RestController@RequestMapping(value = "api/user")public class UserRestController { @Autowired UserService userService; @RequestMapping(value = "/all", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) public List<User> getAll() { return userService.getAll(); }}
UserService
package arma.Arma.Service;import arma.Arma.Repository.UserRepository;import arma.Arma.doman.User;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.stereotype.Service;import java.util.List;@Servicepublic class UserService { @Autowired UserRepository userRepository; public List<User> getAll() { return userRepository.findAll(); }}
User
package arma.Arma.doman;import javax.persistence.*;@Entity@Table(name = "users")public class User { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "user_id", nullable = false) private Long id; @Column(name = "username", nullable = false) private String username; @Column(name = "email", nullable = false) private String email; @Column(name = "password", nullable = false) private String password; @Column(name = "user_type", nullable = false) private UserType type; public Long getId() { return id; } public void setId(Long id) { this.id = id; } public String getUsername() { return username; } public void setUsername(String username) { this.username = username; } public String getEmail() { return email; } public void setEmail(String email) { this.email = email; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; }}
I read tonns of solutions, and none of them helped. Also, it is the first time it appeared, I configured Tomcat, Java, MySql, etc in many machines, and now I'm really helpless.