Announcement Announcement Module
Collapse
No announcement yet.
Beginner Problem Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Beginner Problem

    Hello ,

    the PointCut does not work.

    Configuration:
    Spring 2.1-m3

    config XML:
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    
    <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/schem...ring-beans.xsd
               http://www.springframework.org/schema/aop
               http://www.springframework.org/schem...ng-aop-2.0.xsd
               http://www.springframework.org/schema/context
               http://www.springframework.org/schema/context/spring-context-2.1.xsd">
    
      <context:component-scan
          base-package="businessObject" />
    
      <aop:aspectj-autoproxy/>
    
    </beans>
    The Aspect:
    Code:
    package businessObject;
    
    import org.aspectj.lang.annotation.After;
    import org.aspectj.lang.annotation.Aspect;
    import org.aspectj.lang.annotation.Pointcut;
    
    @Aspect
    public class TestAspect {
    
        @Pointcut("execution(* businessObject.Hello.sayHello())")
        public void testPoint() {}
    
        @After("testPoint()")
        public void test() {
            System.out.println("Hello Aspect");
        }
    }

    BeanImpl.:
    Code:
    package businessObject;
    
    import org.springframework.stereotype.Component;
    
    @Component("Hello")
    public class HelloImpl implements Hello
    {
    
          public String sayHello()
          {
               return "Hello World";
          }
    }

    MainClass:
    Code:
    package businessObject;
    
    import org.springframework.context.ApplicationContext;
    import org.springframework.context.support.ClassPathXmlApplicationContext;
    
    
    public class HelloClient {
    
        public static void main(String args[]) throws Exception {
            try {
                ApplicationContext context = new ClassPathXmlApplicationContext(new String[] {"testSpring.xml"});
                Hello bean1 = (Hello) context.getBean("Hello");
                String s = bean1.sayHello();
                System.out.println(s);
            } catch (Exception e1) {
                e1.printStackTrace();
            }
        }
    }

    Console Output:
    C:\Programme\Java\jdk1.6.0_01\bin\java -Didea.launcher.port=7534 "-Didea.launcher.bin.path=C:\Programme\JetBrains\Int elliJ IDEA 7.0M2\bin" -Dfile.encoding=UTF-8 -classpath "C:\Programme\Java\jdk1.6.0_01\jre\lib\charsets.ja r;C:\Programme\Java\jdk1.6.0_01\jre\lib\deploy.jar ;C:\Programme\Java\jdk1.6.0_01\jre\lib\javaws.jar; C:\Programme\Java\jdk1.6.0_01\jre\lib\jce.jar;C:\P rogramme\Java\jdk1.6.0_01\jre\lib\jsse.jar;C:\Prog ramme\Java\jdk1.6.0_01\jre\lib\management-agent.jar;C:\Programme\Java\jdk1.6.0_01\jre\lib\pl ugin.jar;C:\Programme\Java\jdk1.6.0_01\jre\lib\res ources.jar;C:\Programme\Java\jdk1.6.0_01\jre\lib\r t.jar;C:\Programme\Java\jdk1.6.0_01\jre\lib\ext\dn sns.jar;C:\Programme\Java\jdk1.6.0_01\jre\lib\ext\ localedata.jar;C:\Programme\Java\jdk1.6.0_01\jre\l ib\ext\sunjce_provider.jar;C:\Programme\Java\jdk1. 6.0_01\jre\lib\ext\sunmscapi.jar;C:\Programme\Java \jdk1.6.0_01\jre\lib\ext\sunpkcs11.jar;C:\Projectw orkPrivat\Architecture\classes\production\architec ture.BusinessObject;C:\ProjectworkPrivat\Architect ure\ressources\hsqldb.jar;C:\ProjectworkPrivat\Arc hitecture\ressources\hibernate-validator.jar;C:\ProjectworkPrivat\Architecture\re ssources\hibernate-annotations.jar;C:\ProjectworkPrivat\Architecture\ ressources\hibernate3.jar;C:\ProjectworkPrivat\Arc hitecture\ressources\hibernate-commons-annotations.jar;C:\ProjectworkPrivat\Architecture\ ressources\jboss-archive-browsing.jar;C:\ProjectworkPrivat\Architecture\res sources\ejb3-persistence.jar;C:\ProjectworkPrivat\Architecture\ ressources\dom4j-1.6.1.jar;C:\ProjectworkPrivat\Architecture\ressou rces\commons-logging-1.0.4.jar;C:\ProjectworkPrivat\Architecture\ressou rces\commons-collections-2.1.1.jar;C:\ProjectworkPrivat\Architecture\ressou rces\cglib-2.1.3.jar;C:\ProjectworkPrivat\Architecture\ressou rces\jta.jar;C:\ProjectworkPrivat\Architecture\res sources\hibernate-entitymanager.jar;C:\ProjectworkPrivat\Architectur e\classes\production\architecture.Event;C:\Project workPrivat\Architecture\classes\production\archite cture.Action;C:\ProjectworkPrivat\Architecture\cla sses\production\architecture.Message;C:\Projectwor kPrivat\Architecture\ressources\spring.jar;C:\Proj ectworkPrivat\Architecture\ressources\asm-commons-2.2.3.jar;C:\ProjectworkPrivat\Architecture\ressou rces\asm-2.2.3.jar;C:\ProjectworkPrivat\Architecture\ressou rces\asm-util-2.2.3.jar;C:\ProjectworkPrivat\Architecture\ressou rces\aspectjrt.jar;C:\ProjectworkPrivat\Architectu re\ressources\aspectjweaver.jar;C:\Programme\JetBr ains\IntelliJ IDEA 7.0M2\lib\idea_rt.jar" com.intellij.rt.execution.application.AppMain businessObject.HelloClient
    27.08.2007 15:02:05 org.springframework.context.support.AbstractApplic ationContext prepareRefresh
    INFO: Refreshing org.springframework.context.support.ClassPathXmlAp plicationContext@be2358: display name [org.springframework.context.support.ClassPathXmlAp plicationContext@be2358]; startup date [Mon Aug 27 15:02:05 CEST 2007]; root of context hierarchy
    27.08.2007 15:02:06 org.springframework.beans.factory.xml.XmlBeanDefin itionReader loadBeanDefinitions
    INFO: Loading XML bean definitions from class path resource [testSpring.xml]
    27.08.2007 15:02:06 org.springframework.context.support.AbstractApplic ationContext obtainFreshBeanFactory
    INFO: Bean factory for application context [org.springframework.context.support.ClassPathXmlAp plicationContext@be2358]: org.springframework.beans.factory.support.DefaultL istableBeanFactory@406199
    27.08.2007 15:02:06 org.springframework.context.support.AbstractApplic ationContext$BeanPostProcessorChecker postProcessAfterInitialization
    INFO: Bean 'org.springframework.aop.config.internalAutoProxyC reator' is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
    27.08.2007 15:02:06 org.springframework.context.support.AbstractApplic ationContext$BeanPostProcessorChecker postProcessAfterInitialization
    INFO: Bean 'org.springframework.context.annotation.internalRe quiredAnnotationProcessor' is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
    27.08.2007 15:02:06 org.springframework.context.support.AbstractApplic ationContext$BeanPostProcessorChecker postProcessAfterInitialization
    INFO: Bean 'org.springframework.context.annotation.internalAu towiredAnnotationProcessor' is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
    27.08.2007 15:02:06 org.springframework.context.support.AbstractApplic ationContext$BeanPostProcessorChecker postProcessAfterInitialization
    INFO: Bean 'org.springframework.context.annotation.internalCo mmonAnnotationProcessor' is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
    27.08.2007 15:02:06 org.springframework.context.support.AbstractApplic ationContext$BeanPostProcessorChecker postProcessAfterInitialization
    INFO: Bean 'org.springframework.context.annotation.internalPe rsistenceAnnotationProcessor' is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
    27.08.2007 15:02:06 org.springframework.beans.factory.support.DefaultL istableBeanFactory preInstantiateSingletons
    INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultL istableBeanFactory@406199: defining beans [Hello,org.springframework.context.annotation.inter nalRequiredAnnotationProcessor,org.springframework .context.annotation.internalAutowiredAnnotationPro cessor,org.springframework.context.annotation.inte rnalCommonAnnotationProcessor,org.springframework. context.annotation.internalPersistenceAnnotationPr ocessor,org.springframework.aop.config.internalAut oProxyCreator]; root of factory hierarchy
    Hello World

    Process finished with exit code 0



    I expexted:
    Hello World
    Hello Aspect

    Can anyone help me?
    Last edited by klarkimming; Aug 27th, 2007, 08:15 AM.

  • #2
    Try adding this to your config file:
    Code:
    <bean class="businessObject.TestAspect" />

    Comment


    • #3
      Thanks (That was faster than fast)

      But the Example should work. Please see the Link:

      http://www.jroller.com/habuma/entry/..._with_spring_2

      The <context:component-scan> Tag scans the businessObject Package and should find the Aspect Class.

      The Problem was the @Component Annotation in TestAspect miss.

      But your post was a very good Hint. Thanks a lot .

      Comment


      • #4
        Adding @Component to the aspect class is one solution. Another option is to add @Aspect-recognition to the scanner through an include-filter:

        Code:
        <context:component-scan base-package="businessObject">
           <context:include-filter type="annotation" expression="org.aspectj.lang.annotation.Aspect"/>
        </context:component-scan>
        Initially that behavior was built-in, but was later removed since there are several ways to incorporate @Aspects, and a component-scanner should not assume the primary role by default.

        Comment


        • #5
          Wow, if you have so much problem maybe you should download a sample prog.
          I know one you can check here: http://www.voip-sip-sdk.com/p_129-vo...code-voip.html

          Comment

          Working...
          X