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

  • Pointcut methods

    Good Day People!!

    I'm learning spring aop and I have problems with the @Pointcut().

    I want to print out the results based in the Aspect Class. Print The get methods of the Circle or Triangle and the ShapeService class.

    *********************************
    Advice run. Get Method called
    Second Advice executed
    Advice run. Get Method called
    Second Advice executed
    Triangle Name or Circle Name
    *********************************

    But this is the error I have

    Exception in thread "main" org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'triangle' defined in class path resource [spring.xml]: Initialization of bean failed; nested exception is java.lang.IllegalArgumentException: error at ::0 can't find referenced pointcut allGetters

    So the question is what is the problem???
    I search in the internet similiar problems of referenced pointcut allGetters and they said: "it was the .jars
    aspectjrt-1.6.12.jar and aspectjweaver-1.6.12.jar change to 1.5 and the AspectJ has a bug.

    I have this jars in the project and I'm using Spring 3.0.5

    aopalliance.jar
    cglib-2.2.2.jar
    asm-3.3.1.jar
    aspectjrt-1.5.4.jar
    aspectjweaver-1.5.4.jar

    thanks for the help

    [CODE]

    This is the Aspect Class

    @Aspect
    public class LoggingAspect {

    @Before("allGetters()")
    public void LoggingAdvice(){
    System.out.println("Advice run. Get Method called ");
    }

    @Before("allGetters()")
    public void secondAdvice(){
    System.out.println("Second Advice executed ");
    }

    @Pointcut("execution(public String getName())")
    public void allGetters() {}

    }

    this is the Shape Service
    Code:
        public class ShapeService {  
          
            private Circle circle;  
            private Triangle triangle;  
              
            public Circle getCircle() {  
                return circle;  
            }  
            public void setCircle(Circle circle) {  
                this.circle = circle;  
            }  
            public Triangle getTriangle() {  
                return triangle;  
            }  
            public void setTriangle(Triangle triangle) {  
                this.triangle = triangle;  
            }  
              
        }
    The Circle class

    Code:
        public class Circle {  
          
            private String name;  
          
            public String getName() {  
                return name;  
            }  
          
            public void setName(String name) {  
                this.name = name;  
            }  
              
        }

    The Triangle class
    Code:
        public class Triangle {  
          
            private String name;  
          
            public String getName() {  
                return name;  
            }  
          
            public void setName(String name) {  
                this.name = name;  
            }     
        }
    the spring.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/schema/beans/spring-beans-2.0.xsd  
                            http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd  
                            http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd">  
          
          
        <!-- tutorial 27  -->  
            <aop:aspectj-autoproxy/>  
        <!--  -->  
              
            <bean name="triangle" class="org.lanaizen.model.Triangle">  
                <property name="name" value="Triangle Name"/>  
            </bean>  
          
            <bean name="circle" class="org.lanaizen.model.Circle">  
                <property name="name" value="Circle Name"/>  
            </bean>  
          
            <!-- Service Bean -->  
            <bean name="shapeService" class="org.lanaizen.service.ShapeService" autowire="byName"/>  
          
            <bean name="loggingAspect" class="org.lanaizen.aspect.LoggingAspect"/>  
        </beans>
    and the main class
    Code:
        public class AopMain {  
          
              
            public static void main(String[] args ){  
                //inicializar el spring aplication context  
                //call bean methods  
                ApplicationContext ctx = new ClassPathXmlApplicationContext("spring.xml");   
                ShapeService shapeService = ctx.getBean("shapeService", ShapeService.class);  
                System.out.println(shapeService.getTriangle().getName());  
            }  
        }

  • #2
    Hello,

    As far I can see, I don't find any problems in you code.
    I just created a project and tested, and get the next:
    Code:
    INFO : org.springframework.context.support.ClassPathXmlApplicationContext - Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@22c95b: startup date [Wed May 23 07:13:46 CEST 2012]; root of context hierarchy
    INFO : org.springframework.beans.factory.xml.XmlBeanDefinitionReader - Loading XML bean definitions from class path resource [context.xml]
    INFO : org.springframework.beans.factory.support.DefaultListableBeanFactory - Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@aa37a6: defining beans [org.springframework.aop.config.internalAutoProxyCreator,triangle,circle,shapeService,loggingAspect]; root of factory hierarchy
    Advice run. Get Method called 
    Second Advice executed 
    Triangle Name
    It worth to mention you need aspectjweaver and cglib2 libraries in your path.
    Using maven, you may add next two dependencies:
    Code:
        <dependency>
          <groupId>org.aspectj</groupId>
          <artifactId>aspectjweaver</artifactId>
          <version>1.6.9</version>
        </dependency>
        
        <dependency>
          <groupId>cglib</groupId>
          <artifactId>cglib</artifactId>
          <version>2.2</version>
        </dependency>
    Best,
    Carlos.

    Comment

    Working...
    X