0
I am new to java and I am created a training API and I came across the following problem:
I do the request via Postman, the return of JSON is ok, but if I do a search that does not return anything the message template below is returned:
{
"timestamp": "2020-06-04T23:52:13.722+00:00",
"status": 404,
"error": "Not Found",
"message": "",
"path": "/api/produtos/2"
}
So far so good, what happens is that the attribute message
is not completed.
Use the org.springframework.web.server.ResponseStatusException.ResponseStatusException
spring.
@RestController
@RequestMapping("/api/produtos/")
public class ProdutoController {
@Autowired
ProdutoService produtoService;
@GetMapping("{id}")
public Produto getById(@PathVariable Integer id) {
return produtoService.findById(id)
.orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND, "Produto não encontrado."));
}
}
@Service
public class ProdutoService {
@Autowired
ProdutoRepository produtoRepository;
public Optional<Produto> findById(Integer id){
return produtoRepository.findById(id);
}
}
which version you are using of spring boot?
– Patrick Santana
I used version v2.3.0.RELEASE and the problem is there.
– Patrick Santana
See my answer.
– Patrick Santana