-
May 18th, 2008, 05:25 AM
#1
Cannot proxy the target object
Dear Members,
I tried my first spring example and facing some issues. For some reasons I am failing to proxy the target object, I mean the around advice could not be applied for some reasons. I got this example from "http://static.springframework.org/spring/docs/2.0.x/reference/aop.html"
Please find the code enclosed below. You help will be much appreicated.
================================================== ========
configuration files :
<bean id="fooService" class="x.y.service.DefaultFooService" />
<!-- this is the actual advice itself -->
<bean id="profiler" class="x.y.SimpleProfiler" />
<aop:config proxy-target-class="true">
<aop:aspect ref="profiler">
<aop
ointcut id="theExecutionOfSomeFooServiceMethod"
expression="execution(* x.y.service.FooService.getFoo(String,int))
and args(name, age)"/>
<aop:around
pointcut-ref="theExecutionOfSomeFooServiceMethod" method="profile" />
</aop:aspect>
</aop:config>
================================================== ====
public class SimpleProfiler {
public Object profile(ProceedingJoinPoint call, String name, int age) throws Throwable {
System.out.println("Inside the advice");
StopWatch clock = new StopWatch(
"Profiling for '" + name + "' and '" + age + "'");
try {
clock.start(call.toShortString());
return call.proceed();
} finally {
clock.stop();
System.out.println(clock.prettyPrint());
}
}
================================================== ======
package x.y.service;
public class DefaultFooService implements FooService {
public Foo getFoo(String name, int age) {
return new Foo(name, age);
}
}
================================================== =====
public final class Boot {
public static void main(final String[] args) throws Exception {
BeanFactory ctx = new XmlBeanFactory((Resource) new FileSystemResource("C:\\workspace\\workarea\\sprin g-assignment-01\\spring-assignment2\\src\\x\\y\\plain.xml"));
FooService foo = (FooService) ctx.getBean("fooService");
foo.getFoo("Pengo", 12);
}
}
================================================== ========
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules