-
AspectJ problem
When using the Spring IDE support in Eclipse 3.0 it flags the following:
<bean id="loggingAspect"
class="spring.aspectj.LoggingAspect" factory-method="aspectOf"/>
with the error
'Attribute "factory-method" must be declared for element type "bean"'
I'm using the spring-framework-1.1.1 version
I used the bean definition syntax similar to page 68 in the Spring reference manual, which is for version 1.1.2. So my question is how would I do this in version 1.1.1?
-
That syntax appears to be correct - have you tried running the application. This may just be a problem with Spring IDE.
Rob
-
Sometimes the aspect works other times I get this error
java.lang.VerifyError: (class: spring/aspectj/LoggingAspect, method: <clinit> signature: ()V) Stack size too large
-
Can you post the code for your LoggingAspect - also are you using any special VM startup params that affect the stack size?
Rob
-
The aspect worked great the first time I ran the application, every time after I get
java.lang.VerifyError: (class: spring/aspectj/LoggingAspect, method: <clinit> signature: ()V) Stack size too large
I'm not using any special VM startup params that affect the stack size.
Here's the aspect:
import org.apache.log4j.*;
import org.aspectj.lang.*;
public aspect LoggingAspect {
private final Logger logger = Logger.getLogger("trace aspect");
LoggingAspect() {
logger.setLevel(Level.ALL);
}
pointcut loggedOperations()
: (call(* *.*(..)) || call(*.new(..)))
&& ! within(LoggingAspect);
before() : loggedOperations() {
if(logger.isEnabledFor(Level.INFO)) {
Signature sig = thisJoinPointStaticPart.getSignature();
logger.log(Level.INFO,
"Entering [" + sig.getDeclaringType().getName()
+ "." + sig.getName() + "]");
}
}
after() : loggedOperations() {
if(logger.isEnabledFor(Level.INFO)) {
Signature sig = thisJoinPointStaticPart.getSignature();
logger.log(Level.INFO,
"Exiting [" + sig.getDeclaringType().getName()
+ "." + sig.getName() + "]");
}
}
}
-
I think what I'm trying to do is unnecessary for my particular application. If I don't include an aspect bean definition for the logging aspect in my application context the aspect works fine and there's no deployment problems. If I do, the spring IDE in eclipse flags it as an error and during deployment I sometimes get an error concerning the stack size and sometimes I don't. If the weaving takes place at compilation, before I even deploy the application, why would the spring container ever need to instantiate the aspect? Or more generally how useful is it to obtain a reference to the single aspect instance in a JVM through the aspectOf() method?
Say for instance:
public class X {
private LoggingAspect loggingAspect;
public void setLoggingAspect(LoggingAspect loggingAspect) {
this.loggingAspect = loggingAspect;
}
public void printTotalLinesLogged() {
int totalLinesLogger = this.loggingAspect.getTotalLinesLogged();
System.out.println("Total lines logged: " + totalLinesLogged);
}
}
Is that what would be possible in spring if I included a bean definition for my particular aspect, provided of course there was a public getTotalLinesLogged() method defined in LoggingAspect?