Fiz uma aplicação bem simples, pra salvar um cliente com poucos dados a partir do SpringBoot, a aplicação sobe, roda, eu vou no postman coloco o JSON e ocorre o erro 500, eu não consigo resolver, tem como me ajudar? CÓDIGO CONTROLLER
import jakarta.validation.Valid;
import org.springframework.beans.BeanUtils;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
@RestController
@CrossOrigin(origins = "*", maxAge = 3600)
@RequestMapping("/cliente-data")
public class ClienteController {
private final ClienteService clienteService;
public ClienteController(ClienteService clienteService) {
this.clienteService = clienteService;
}
@PostMapping
public ResponseEntity<Object> saveClienteData(@RequestBody @Valid ClienteDTO clienteDTO) {
var clienteModel = new ClienteModel();
BeanUtils.copyProperties(clienteDTO, clienteModel);
return ResponseEntity.status(HttpStatus.CREATED).body(clienteService.save(clienteModel));
}
}`
CÓDIGO SERVICE
package br.com.tech.erick.consultoria.services;
import br.com.tech.erick.consultoria.models.ClienteModel; import br.com.tech.erick.consultoria.repositories.ClienteRepository; import jakarta.transaction.Transactional; import org.springframework.stereotype.Service;
@Service public class ClienteService {
//Injetando a dependencia(poderia ser por construtor tbm)
private final ClienteRepository clienteRepository;
public ClienteService(ClienteRepository clienteRepository) {
this.clienteRepository = clienteRepository;
}
//Métodos destrutivos ou construtivos bom usar transactional!
@Transactional
public ClienteModel save(ClienteModel clienteModel) {
return clienteRepository.save(clienteModel);
}
}
CÓDIGO REPOSITORY
package br.com.tech.erick.consultoria.repositories;
import br.com.tech.erick.consultoria.models.ClienteModel; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository;
import java.util.UUID;
@Repository
public interface ClienteRepository extends JpaRepository<ClienteModel, UUID> {
}
`
JSON: