Results 1 to 3 of 3

Thread: Cannot proxy the target object

  1. #1
    Join Date
    May 2008
    Posts
    2

    Default 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. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,629

    Default

    Use an ApplicationContext (FileSystemXmlApplicationContext) instead of a BeanFactory. Read chapter 3 of the reference guide which explains the difference.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  3. #3
    Join Date
    May 2008
    Posts
    2

    Default

    Thanks for you help Marten. It works fine. Appreciate your help.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •