I have a spring boot application where I am currently running it with mvnw spring-boot:run
I have setup a custom exception like so
@ResponseStatus(value = HttpStatus.BAD_REQUEST)
public class InvalidEntityException extends Exception {
public InvalidEntityException() {
super();
}
public InvalidEntityException(String message) {
super(message);
}
public InvalidEntityException(String message, Throwable cause) {
super(message, cause);
}
public InvalidEntityException(Throwable cause) {
super(cause);
}
}
In a method in a rest controller I can throw this exception and in the Spring Boot logs I can see
Resolved [foo.bar.InvalidEntityException: Error message.]
And in the JSON response my data looks like this:
error: "Bad Request"
message: "Error message"
path: "/resource/request"
status: 400
timestamp: "2021-06-06T04:12:39.759+00:00"
However, when I go and run mvn clean package and run my output .jar file using java -jar out.jar and call a method on this controller, I no longer see the message Resolved [foo.bar.InvalidEntityException: Error message.] and my JSON response looks like this, with the message missing.
error: "Bad Request"
message: ""
path: "/resource/request"
status: 400
timestamp: "2021-06-06T04:12:39.759+00:00"
What is the difference between running my springboot application from mvnw spring-boot:run to running the .jar? I want the same behaviour where error messages are resolved