Announcement Announcement Module
Collapse
No announcement yet.
Trouble using factory-method="aspectOf" Error Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Trouble using factory-method="aspectOf" Error

    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.

    Code:
    -javaagent:shared-lib/AspectJWeaver/aspectjweaver.jar
    Error 2
    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
    Code:
    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
    The application context i.e. myapp-servlet.xml

    Code:
    <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>
    my aop.xml

    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


    Code:
    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;
    	}
    }
    the Controller

    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;
    	} 
    
    }
    Any help will be greatly appreciated!!
    Last edited by quophyie; Feb 17th, 2010, 08:04 AM.

  • #2
    I have resolved this problem but why it works now, i have no idea. Basically, as I am using Eclipse, I had to convert my project to an AspectJ project i.e. right click project > Configure > Convert to AspectJ Project.

    After doing that, it worked but I am still at a loss as to why.

    Also, it turns out that you can advice controllers. After doing as described above the advice on the controllers started to work. I read somewhere that you could not apply aspects to spring controllers. Either I was misinformed or I have got something totally wrong. Still miffed

    Comment

    Working...
    X