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
The Circle classCode: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; } }
Code:public class Circle { private String name; public String getName() { return name; } public void setName(String name) { this.name = name; } }
The Triangle class
the spring.xmlCode:public class Triangle { private String name; public String getName() { return name; } public void setName(String name) { this.name = name; } }
and the main classCode:<?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>
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()); } }


Reply With Quote