Ошибка Java Spring Rest API 404 - PullRequest
       10

Ошибка Java Spring Rest API 404

0 голосов
/ 29 апреля 2018

Я делаю RestApi в Java Spring (Gradle). Когда компилируете код и пробуете его в Postman, он возвращается с 404. Я не знаю почему, и это очень раздражает.

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;

@Service
public class UserService {

    @Autowired
    UserRepository userRepository;

    public List<User> getAll() {
        return userRepository.findAll();
    }
}

Пользователь

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;
    }
}

Я прочитал множество решений, и ни одно из них не помогло. Кроме того, это впервые, когда я настроил Tomcat, Java, MySql и т. Д. На многих машинах, и теперь я действительно беспомощен.

...