Note that there are some explanatory texts on larger screens.

plurals
  1. POSeeing odd behavior when learning SpringAOP using @AspectJ style
    primarykey
    data
    text
    <p>Iam a new bee to Spring Framework and i am referring to documentation available with spring projects.</p> <p>In the process i am also learning a new concept AOP. I am following the spring documentation to try out some samples <a href="http://docs.spring.io/spring/docs/current/spring-framework-reference/html/aop.html" rel="nofollow">http://docs.spring.io/spring/docs/current/spring-framework-reference/html/aop.html</a></p> <p>I tried to use "@AspectJ" style for my first Aspect Helloworld using Spring AOP.</p> <p>This is my context config file</p> <pre><code>&lt;beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"&gt; &lt;aop:aspectj-autoproxy expose-proxy="false" /&gt; &lt;context:annotation-config&gt;&lt;/context:annotation-config&gt; &lt;bean id="aoProgrammingAspectJ" class = "com.AOProgramming.AOProgrammingAspectJ"&gt; &lt;/bean&gt; &lt;bean id="aoProgrammingImpl" class = "com.AOProgramming.AOProgrammingImpl"&gt; &lt;/bean&gt; &lt;/beans&gt; </code></pre> <p>This is a simple interface</p> <pre><code>package com.AOProgramming; public interface AOProgrammingInterface { public void startAspecting(); } </code></pre> <p>I implement this interface </p> <pre><code>package com.AOProgramming; public class AOProgrammingImpl implements AOProgrammingInterface { @Override public void startAspecting() { System.out.println("THe Aspecting has just begun for :"); } } </code></pre> <p>This is where i am defining the aspect definition for pointcut and advice</p> <pre><code>package com.AOProgramming; import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Before; import org.aspectj.lang.annotation.Pointcut; @Aspect public class AOProgrammingAspectJ { @Pointcut("execution( * com.AOProgramming.*.*(..))") public void cuttingOne() {} @Before("cuttingOne()") public void adviceCuttingOne1(){ System.out.println("This is the at the beginning"); } } </code></pre> <p>This is my actual INVOKER class</p> <pre><code>package com.AOProgramming; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; public class AOProgrammingInvokerApp { public static void main(String[] args){ ApplicationContext context = new ClassPathXmlApplicationContext("AOProgramming-servlet.xml"); AOProgrammingImpl obj = (AOProgrammingImpl) context.getBean("aoProgrammingImpl"); obj.startAspecting(); } } </code></pre> <p>When i tried to execute the sample i am getting the following Error</p> <pre><code>Exception in thread "main" java.lang.ClassCastException: com.sun.proxy.$Proxy6 cannot be cast to com.AOProgramming.AOProgrammingImpl at com.AOProgramming.AOProgrammingInvokerApp.main(AOProgrammingInvokerApp.java:12) </code></pre> <p>I am trying to re-read the complete page still i have the same issue also not getting enough material dealing with latest Spring AOP samples. All pre-dates to 2002 or 2008 which has different way of explaining SpringAOP.</p> <p>Can someone help me to understand what i missed here</p> <p>Appreciate your help</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload