Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Whitelabel Error Page #17

Open
LuizSorrentino opened this issue Oct 16, 2024 · 0 comments
Open

Whitelabel Error Page #17

LuizSorrentino opened this issue Oct 16, 2024 · 0 comments

Comments

@LuizSorrentino
Copy link

Bom dia,

Não é a a primeira vez que esse erro acontece mesmo eu seguindo todos os passo a passo, eu não faço ideia do que ocorre e já não sei o que fazer.
"
This application has no explicit mapping for /error, so you are seeing this as a fallback.

Wed Oct 16 10:59:23 BRT 2024
There was an unexpected error (type=Not Found, status=404).
"
O curioso é que não apresenta nenhum erro no terminal, então não há como rastrear.

Meu codigo das principais e referente ao caso

package springjpa.controller;

import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.support.ServletUriComponentsBuilder;
import springjpa.model.User;
import springjpa.repository.UserRepository;
import springjpa.service.UserService;

import java.net.URI;
import java.util.List;

@RestController
@RequestMapping(value = "/users")
public class UserController {

private final UserService userService;
private final UserRepository userRepository;

public UserController(UserService userService, UserRepository userRepository) {
    this.userService = userService;
    this.userRepository = userRepository;
}

@GetMapping("/{id}")
public ResponseEntity<User> findById(@PathVariable Long id) {
    var user = userService.findById(id);
    return ResponseEntity.ok(user);
}

@PostMapping()
public ResponseEntity<User> create(@RequestBody User userToCreate) {
    var userCreated = userService.create(userToCreate);
    URI location = ServletUriComponentsBuilder.fromCurrentRequest()
            .path("/{id}")
            .buildAndExpand(userCreated.getId())
            .toUri();

    return ResponseEntity.created(location).body(userCreated);
}

@DeleteMapping
public ResponseEntity<User> deleteById(@RequestBody User userToDelete) {
    userService.deleteById(userToDelete.getId());
    return ResponseEntity.noContent().build();
}

@GetMapping
public List<User> findAll() {
    return userService.findAll();
}

@PutMapping()
public ResponseEntity<User> update(@RequestBody User userToUpdate) {
    return null;
}

}

do repository

package springjpa.repository;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import springjpa.model.User;

@repository
public interface UserRepository extends JpaRepository<User, Long> {

}

da implementação
package springjpa.service.impl;

import org.springframework.stereotype.Service;
import springjpa.model.User;
import springjpa.repository.UserRepository;
import springjpa.service.UserService;
import java.util.List;
import java.util.NoSuchElementException;

@service
public class UserServiceImpl implements UserService {

private final UserRepository userRepository;

public UserServiceImpl(UserRepository userRepository) {
    this.userRepository = userRepository;
}

@Override
public User findById(Long id) {
    return userRepository.findById(id).orElseThrow(NoSuchElementException::new);
}

@Override
public User create(User userToCreate) {
    if (userToCreate.getId() != null && userRepository.existsById(userToCreate.getId())) {
        throw new IllegalArgumentException("User ID already exists!");
    }
    return userRepository.save(userToCreate);
}

@Override
public List<User> findAll() {

    return null;
}

@Override
public User save(User user) {
    userRepository.save(user);
    return user;
}

só não tenho o yml ainda, mas pelo que sei ele serve apenas pra ter acesso a tabela correto

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant