Java Reference
In-Depth Information
public double kilometerToMile(double kilometer) {
double mile = kilometer * 0.62;
System.out.println(kilometer + " kilometer = " + mile + " mile");
return mile;
To enable AspectJ annotation support for this application, you just define an empty XML
element, <aop:aspectj-autoproxy> , in your bean configuration file. Moreover, you must add the
aop schema definition to your <beans> root element. When the Spring IoC container notices the
<aop:aspectj-autoproxy> element in your bean configuration file, it will automatically create proxies
for your beans that are matched by your AspectJ aspects.
<beans xmlns=""
<aop:aspectj-autoproxy />
<bean id="arithmeticCalculator"
calculator.ArithmeticCalculatorImpl" />
<bean id="unitCalculator"
class="com.apress.springenterpriserecipes.calculator.UnitCalculatorImpl" />
1-11. Declaring Aspects with AspectJ Annotations
Since merging with AspectWerkz in AspectJ version 5, AspectJ supports aspects written as POJOs
annotated with a set of AspectJ annotations. Aspects of this kind are also supported by the Spring AOP
framework, although they must be registered in the Spring IoC container to take effect.
You register AspectJ aspects in Spring simply by declaring them as bean instances in the IoC container.
With AspectJ enabled in the Spring IoC container, it will create proxies for your beans that are matched
by your AspectJ aspects.
Written with AspectJ annotations, an aspect is simply a Java class with the @Aspect annotation. An
advice is a simple Java method with one of the advice annotations. AspectJ supports five types of advice
annotations: @Before , @After , @AfterReturning , @AfterThrowing , and @Around .
Search WWH ::

Custom Search