Hi
I have an aspectj aspect which I want to use to advice an MVC controller as Spring AOP does not work for controllers. As explained in section "6.8.3. Configuring AspectJ aspects using Spring IoC", one has to add the "factory-method" with a value of "aspectOf" to the bean configuration of the aspect as I have done below i.e. "factory-method='aspectOf'". However, when I try and build the application, I get error 1 below i.e." No matching factory method found: factory method 'aspectOf'". If I remove the "factory-method='aspectOf'" attribute from the bean definition (aspect) in the application context, I get error 2 below. I dont understand why this is. I dont think I have to define the aspectOf method in my aspect as if I'm not mistaken, this is provided automatically, so I'm not too sure what I've got wrong. I am using the aspectj weaver and this has been added as shared library to OC4J. I am using OC4J 10.1.3.5 and I start the server with JVM flags.
Error 2Code:-javaagent:shared-lib/AspectJWeaver/aspectjweaver.jar
Code:org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'systemArchitecture' defined in ServletContext resource [/WEB-INF/myapp-servlet.xml]: No matching factory method found: factory method 'aspectOf'
Error 2
The application context i.e. myapp-servlet.xmlCode:org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'loginController' defined in ServletContext resource [/WEB-INF/myapp-servlet.xml]: Error setting property values; nested exception is org.springframework.beans.PropertyBatchUpdateException; nested PropertyAccessExceptions (1) are: PropertyAccessException 1: org.springframework.beans.MethodInvocationException: Property 'loginFormObject' threw exception; nested exception is java.lang.NoSuchMethodError: com.raptorsoftdynamics.myapp.aspects.SystemArchitecture.aspectOf()Lcom/raptorsoftdynamics/myapp/aspects/SystemArchitecture; at .... Caused by: org.springframework.beans.PropertyBatchUpdateException; nested PropertyAccessExceptions (1) are: PropertyAccessException 1: org.springframework.beans.MethodInvocationException: Property 'loginFormObject' threw exception; nested exception is java.lang.NoSuchMethodError: com.raptorsoftdynamics.myapp.aspects.SystemArchitecture.aspectOf()Lcom/raptorsoftdynamics/myapp/aspects/SystemArchitecture; at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:102) at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:58) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1338) ... 37 more
my aop.xmlCode:<bean id ="systemArchitecture" class = "com.raptorsoftdynamics.iBankUI.aspects.SystemArchitecture" factory-method="aspectOf"/> <bean id = "registrationController" class="com.raptorsoftdynamics.myapp.controllers.RegistrationController" > <property name="pages"> <list> <value>registrationPersonalDetails</value> <value>registrationContactDetails</value> <value>registrationLoginAndSecurityDetails</value> <value>calendar</value> </list> </property> <property name="userBean" ref = "userBean"/> <property name="registrationModel" ref="registrationModel"/> <property name="commandClass" value = "com.raptorsoftdynamics.myapp.formObjects.RegistrationModel"/> <property name="commandName" value="registrationModel"/> </bean>
Code:<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE aspectj PUBLIC "-//AspectJ//DTD//EN" "http://www.eclipse.org/aspectj/dtd/aspectj.dtd"> <aspectj> <weaver> <!-- only weave classes in our application-specific packages --> <include within="com.raptorsoftdynamics.myapp.controllers.*"/> </weaver> <aspects> <!-- weave in just this aspect --> <aspect name="com.raptorsoftdynamics.myapp.aspects.SystemArchitecture"/> </aspects> </aspectj>
The Aspect
the ControllerCode:package com.raptorsoftdynamics.myapp.aspects; import org.apache.log4j.Logger; import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lang.annotation.Around; import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Pointcut; @Aspect public class SystemArchitecture { //Pointcuts Logger logger; @Pointcut("execution (* com.raptorsoftdynamics..*.*(..))") public void anyMethod(){} //Advice @Around("anyMethod()") public Object log(ProceedingJoinPoint pjp) throws Throwable{ logger = Logger.getLogger(pjp.getTarget().getClass().getName()); logger.debug("Entering method "+pjp.getSignature()); Object retVal = pjp.proceed(); logger.debug("Exiting method "+pjp.getSignature()); return retVal; } }
Any help will be greatly appreciated!!Code:public class RegistrationController extends AbstractWizardFormController { .... public void sayHello(){ System.out.println("I am saying hello"); } @Override protected ModelAndView processFinish(HttpServletRequest request, HttpServletResponse response, Object command, BindException errors) throws Exception { // TODO Auto-generated method stub this.sayHello(); registrationModel = (RegistrationModel)command; userBean.register(model.getUsername(), model.getPassword(), model.getConfirmedPassword(), model.getSecurityQuestion(), model.getSecurityNumber(), model.getConfirmedSecurityNumber(), model.getMemorableData(), System.currentTimeMillis(), model.getCustomerDetails(), model.getContactDetails(), model.getConfirmedEmail()); ModelAndView mv = new ModelAndView(); mv.setViewName("registrationSuccessful"); mv.addObject("registrationModel", registrationModel); return mv; } }


Reply With Quote