Announcement Announcement Module
Collapse
No announcement yet.
Cannot proxy the target object Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • 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 "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">
    <aopointcut 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);
    }
    }

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

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

    Comment


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

      Comment

      Working...
      X