25.02.2015 Views

Introducing Spring Framework

Introducing Spring Framework

Introducing Spring Framework

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 8 ■ Give Advice to Your <strong>Spring</strong> Application<br />

}<br />

}<br />

log.error("@@@(AROUND) Throws an exception: " + ex.getMessage());<br />

throw ex;<br />

}<br />

Listing 8-10 shows the implementation of the invoke method that has the MethodInvocation class as a<br />

parameter, which is in fact the object that it is advising. With the MethodInvocation class you can get the method that<br />

was intercepted and its arguments. You can execute the method by calling proceed() to get the result of the execution.<br />

Next, let’s modify your XML to point to your new advice, the AroundLoggingModule class as shown in Listing 8-11.<br />

Listing 8-11. mydocuments-aop-context.xml<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

aroundLogging<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

Running the unit test (see Listing 8-5) with<br />

gradle :ch08:test<br />

you will get the following output:<br />

2014-02-23 20:46:25,679 DEBUG [main] Using <strong>Spring</strong> AOP:<br />

2014-02-23 20:46:25,689 DEBUG [main] @@@@(AROUND-BEFORE) Method called: findByType<br />

2014-02-23 20:46:25,689 DEBUG [main] @@@@(AROUND-BEFORE) Argument passed:Type(name: WEB,<br />

description: Web Link, extension: .url)<br />

101

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!