I have the following code:
@Path("/users/{id}")
public class UserResource {
@Autowired
private UserDao userDao;
@GET
@Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
public User getUser(@PathParam("id") int id) {
User user = userDao.getUserById(id);
if (user == null) {
throw new NotFoundException();
}
return user;
}
If I request for a user that doesn't exists, like /users/1234
, with "Accept: application/json
", this code returns an HTTP 404
response like one would expect, but returns Content-Type
sets to text/html
and a body message of html. Annotation @Produces
is ignored.
Is it a problem of code or a problem of configuration?