Announcement Announcement Module
No announcement yet.
Cannot proxy the target object Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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 ""

    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">
    <aopointcut id="theExecutionOfSomeFooServiceMethod"
    expression="execution(* x.y.service.FooService.getFoo(String,int))
    and args(name, age)"/>
    pointcut-ref="theExecutionOfSomeFooServiceMethod" method="profile" />


    ================================================== ====

    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 {
    return call.proceed();
    } finally {
    ================================================== ======

    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);

    ================================================== ========

  • #2
    Use an ApplicationContext (FileSystemXmlApplicationContext) instead of a BeanFactory. Read chapter 3 of the reference guide which explains the difference.


    • #3
      Thanks for you help Marten. It works fine. Appreciate your help.