Managing exceptions
Spring 5.0 has built-in API classes such as HandlerExceptionResolver and @AdviceController to handle @Controller exceptions, but this recipe will create another way to manage exceptions through an improvised handler implemented using the AOP paradigm.
Getting started
Open ch05 and add another aspect component that will monitor all methods of EmployeeServiceImpl and will catch all types of exceptions once encountered.
How to do it...
Let us improvise exception handling using AOP concepts by doing these steps:
- Just like in the previous recipe, verify if
Employeemodels classes and its service implementations are in their respective packages. We will still be using theJdbctemplate-based CRUD transactions. - Other than transactions,
@Aspectcan also be used to trace and log some exceptions. Let us now add an aspect namedExceptionUpdateAspectin the packageorg.packt.aop.transaction.corethat will contain two@AfterThrowingadvices, namelylogExceptionUpdateEmp(), which will be...