Human Resources Example - Configuring the Audit Behavior
This additional configuration is all that is needed to apply the audit aspect at run-time, adding auditing behavior to the Human Resources service. You can test this by running the client using the run.sh script. A log directory is created on start-up alongside the lib directory when the AuditAspect bean is created by the Microcontainer. Each deployment of the Human Resources service causes a new log file to appear within the log directory. The log file contains a record of any calls made from the client to the service. It is named something similar to auditLog-28112007-163902, and contains output similar to Example 5.4, “Example AOP Log Output�. Example 5.4. Example AOP Log Output Method: getEmployees Return: [] Method: addEmployee Args: (Santa Claus, 1 Reindeer Avenue, Lapland City - 25/12/1860) Return: true Method: getSalary Args: (Santa Claus, null - Birth date unknown) Return: 10000 Method: getEmployees Return: [(Santa Claus, 1 Reindeer Avenue, Lapland City - 25/12/1860)] Method: isHiringFreeze Return: false Method: getEmployees Return: [(Santa Claus, 1 Reindeer Avenue, Lapland City - 25/12/1860)] Method: getSalaryStrategy To remove the auditing behavior, comment out the relevant fragments of XML in the deployment descriptor and restart the application. Warning The order of deployment matters. Specifically each aspect must be declared before the beans that it applies to, so that the Microcontainer deploys them in that order. This is because the Microcontainer may need to alter the bytecode of the normal bean class to add the cross-cutting logic, before it creates an instance and stores a reference to it in the controller. If a normal bean instance has already been created, this is not possible.