0

I am using spring aop and have defined some aspects. Spring LTW is enabled on my tomcat. In my application context:

<context:load-time-weaver/>
<aop:aspectj-autoproxy proxy-target-class="false"/>

Aspects are working fine too! but the target class is proxied! causing ClassCastException: can not convert $Proxy... Note that I don't my target classes to be proxied!

AmirMV
  • 215
  • 1
  • 11

1 Answers1

0

If you are using AspectJ LTW you only need the tag

<context:load-time-weaver/> 

in your Spring context file. So you can remove,

<aop:aspectj-autoproxy proxy-target-class="false"/>

If the target class is proxied is because LTW with AspectJ is not configured in a good way, for this reason is not AspectJ who is handling your advices, and is Spring who is doing that. For this reason you see proxy based target class.

Check this links,

http://static.springsource.org/spring/docs/3.2.2.RELEASE/spring-framework-reference/html/aop.html#aop-aj-ltw

http://static.springsource.org/spring/docs/3.2.2.RELEASE/spring-framework-reference/html/aop.html#aop-aj-ltw-environments

  • So, you're saying that if I use spring AOP with LTW, there is no way for target classes not to be proxied? (I don't want to use AspectJ compiler!) – AmirMV Jun 10 '13 at 09:05
  • If you want LTW you will have to use AspectJ compiler. Is more, if you want LTM you will have to use a META-INF/aop.xml file. Spring itself is not able of using LTW, and only is able of creating proxy based aspects. If you want LTW you need to introduce AspectJ. You can integrate ApectJ with Spring (even the dependency injection inside your AspectJ advices), but you can't have LTW without AspectJ and only using Spring. –  Jun 10 '13 at 11:07