When a company colleague locates a bug, it finds that spring's default transaction only supports the runtime exception rollback, and for non-runtime exceptions like SqlException, the default transaction mechanism cannot be processed, and a workaround is found:
1. When capturing SqlException, throw a runtimeexception and its subclasses, for example:
try {
Xxx
} catch (Exception e) {
throw new Moduleexception ();
}
The moduleexception here is the company's own definition of the class that inherits the RuntimeException.
2. Add a configuration that captures specific exceptions in spring
This is because RuntimeException is a subclass of exception, so capturing all of the exception directly can also achieve the purpose of the transaction rollback when the sqlexception occurs.
Resolve run-time exceptions such as SqlException are not supported by spring transaction management by default