Back Forum Reply New

Error with separate pointcut definition than advice

Hi, I am getting an error if I declare the pointcuts separately in another class and then try accessing them in the advice in Spring 2.0. Here is the sample code I wrote:

Code:
HelloService.java
=============
package mohnish.aop.domain;

public class HelloService {

public void sayHello(){

System.out.println(quot;hello world!quot;);
}
}AppPointcut.java
=============
package mohnish.aop.pointcut;

import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;

@Aspect
public class AppPointcut {

@Pointcut(quot;execution(* mohnish.aop.domain.HelloService.sayHello())quot;)
public void helloMethod(){}

}AppAdvice.java
============
package mohnish.aop.advice;

import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;

@Aspect
public class AppAdvice {

@Before(quot;mohnish.aop.pointcut.AppPointcut.helloMethod()quot;)
//@Before(quot;execution(* mohnish.aop.domain.HelloService.sayHello())quot;)
public void sayHelloAgain(){
System.out.println(quot;Hello - AOP stylequot;);
}
}

AppMain.java
==========
package mohnish.aop;

import mohnish.aop.domain.HelloService;

import org..context.ApplicationContext;
import org..context.support.ClassPathXmlApplicationContext;

public class AppMain {

public static void main(String[] args) {

ApplicationContext ctx = new ClassPathXmlApplicationContext(quot;application.xmlquot;);

HelloService helloService = (HelloService)ctx.getBean(quot;helloServicequot;);
helloService.sayHello();

}
}
The configuration file is as below:Code:
application.xml
===========
lt;?xml version=quot;1.0quot; encoding=quot;UTF-8quot;?gt;
lt;beans xmlns=quot;schema/beansquot;  xmlns:xsi=quot;2001/XMLSchema-instancequot;     xmlns:aop=quot;schema/aopquot;  xsi:schemaLocation=   quot;schema/beans    schema/beans/spring-beans.xsd    schema/aop    schema/aop/spring-aop.xsdquot;gt;

lt;aop:aspectj-autoproxy/gt;

lt;bean id=quot;helloServicequot; class=quot;mohnish.aop.domain.HelloServicequot;/gt;

lt;bean id=quot;pointcutsquot; class=quot;mohnish.aop.pointcut.AppPointcutquot;/gt;      
lt;bean id=quot;advicesquot; class=quot;mohnish.aop.advice.AppAdvicequot;/gt;

lt;/beansgt;
Now, I get the following error when trying to run the code:Code:
Exception in thread quot;mainquot; org..beans.factory.BeanCreationException: Error creating bean with name 'helloService' defined in class path resource [application.xml]: Initialization of bean failed; nested exception is java.lang.IllegalArgumentException: error at ::0 can't find referenced pointcut helloMethod
Caused by: java.lang.IllegalArgumentException: error at ::0 can't find referenced pointcut helloMethod
at org.aspectj.weaver.tools.PointcutParser.parsePointcutExpression(PointcutParser.java:315)
at org..aop.aspectj.AspectJExpressionPointcut.buildPointcutExpression(AspectJExpressionPointcut.java:172)
at org..aop.aspectj.AspectJExpressionPointcut.checkReadyToMatch(AspectJExpressionPointcut.java:162)
at org..aop.aspectj.AspectJExpressionPointcut.getClassFilter(AspectJExpressionPointcut.java:103)
at org..aop.support.AopUtils.canApply(AopUtils.java:190)

Interesting point to note is that, if I do not refer to the pointcut in my advice and define the pointcut in-place, everything works fine! Just uncomment the commented line in AppAdvice.java and comment the line above it. It would work fine!

I noticed that someone else was also facing the same issue, and Mr. Ramnivas was helping with the solution. The guy seemed to be facing the same situation as am I but do not how it worked well when Mr. Ramnivas ran it !!!

Any help as to what am I doing wrong ?

Regards,
Mohnish
======

Are you running the code under Java 6? Such a bug is seen under Java 6. If so, just run your code with Java 5.

-Ramnivas

I was just trying to upgrade to Java6 too and I found that bug...Are times of fixing this bug known? Thanks..
¥
Back Forum Reply New