Announcement Announcement Module
Collapse
No announcement yet.
NoSuchMethodException when Aspecting classes Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • NoSuchMethodException when Aspecting classes

    Hi everyone,

    I'm new to Aspects and I'm having trouble configuring them inside Spring, I have some questions to ask:

    First, configuration issues, I've got defined these beans provided by Appfuse (2.0):
    Code:
    <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:tx="http://www.springframework.org/schema/tx"
           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/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd"
           default-lazy-init="true">
    
        <!-- =================================================================== -->
        <!-- AOP: Configuration and Aspects                                      -->
        <!-- =================================================================== -->
        <aop:config>
            <aop:advisor id="userManagerTx" advice-ref="userManagerTxAdvice" pointcut="execution(* *..service.UserManager.*(..))" order="0"/>        
            <aop:advisor id="userManagerSecurity" advice-ref="userSecurityAdvice" pointcut="execution(* *..service.UserManager.saveUser(..))" order="1"/>
            <aop:advisor id="managerTx" advice-ref="txAdvice" pointcut="execution(* *..service.*Manager.*(..))" order="2"/>
        </aop:config>
        
        <!-- Enable @Transactional support -->
        <tx:annotation-driven/>
        
        <!-- Fix bug in Spring 2.0.6: http://issues.appfuse.org/browse/APF-887 -->
        <bean class="org.springframework.transaction.aspectj.AnnotationTransactionAspect" factory-method="aspectOf" dependency-check="none" lazy-init="false">
            <property name="transactionManager" ref="transactionManager"/>
        </bean>
        
        <!-- Enable @AspectJ support -->
        <aop:aspectj-autoproxy/>
    
        <!-- Enable @Configured support -->
        <aop:spring-configured/>
        
        <tx:advice id="txAdvice">
            <tx:attributes>
                <!-- Read-only commented out to make things easier for end-users -->
                <!-- http://issues.appfuse.org/browse/APF-556 -->
                <!--tx:method name="get*" read-only="true"/-->
                <tx:method name="*"/>
            </tx:attributes>
        </tx:advice>
    
        <tx:advice id="userManagerTxAdvice">
            <tx:attributes>
                <tx:method name="save*" rollback-for="UserExistsException"/>
            </tx:attributes>
        </tx:advice>
        
        <bean id="userSecurityAdvice" class="org.appfuse.service.UserSecurityAdvice"/>
        
        [...]
    These beans are defined inside an applicationContext file inside one of appfuse jars, so I cannot change them (although I do overwrite some other appfuse bean). I do need to keep the aop:config section, as it being used by our application.

    And I've also defined (in our own applicationContext file) a couple of beans to implement logging when some subpackaging is detected or when detecting some annotations:

    Code:
      <bean id="aLogInterceptor" class="com.bungee.aspects.AnnotationLoggerInterceptor" />
      <bean id="cpLogInterceptor" class="com.bungee.aspects.PackagesLoggerInterceptor" />
    Next the @AspectJ class:

    Code:
    @Aspect
    public class PackagesLoggerInterceptor {
    
        @Before( "execution( * com.bungee..*.*(..) ) && !execution( * com.bungee.aspects.*.*(..) )" )
        public void beforeMethod( JoinPoint jp ) {
    	// logging in here
        }
        
        @AfterReturning( pointcut = "execution( * com.bungee..*.*(..) ) && !execution( * com.bungee.aspects.*.*(..) )", returning="retVal" )
        public void afterMethod( JoinPoint jp, Object retVal ) {
    	// more logging in here...
        }
        
        @AfterThrowing( pointcut = "execution( * com.bungee..*.*(..) ) && !execution( * com.bungee.aspects.*.*(..) )", throwing="ex" )
        public void afterException( JoinPoint jp, Throwable ex ) {
    	// ... and finish logging here
        }
        
    }
    Ok, first problem in here, I've got some Struts2 actions under package com.bungee.webapp.action. Each time one of those classes gets invoked I've got the same type of Exception:


    Code:
    java.lang.NoSuchMethodException: $Proxy361.initHome()
    	at java.lang.Class.getMethod(Class.java:1605)
    	at org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.getActionMethod(AnnotationValidationInterceptor.java:55)
    	at org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:41)
    	at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:86)
    	at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
    	at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
    	at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
    	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
    	at com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:123)
    	at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
    	at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
    	at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
    	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
    	at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:167)
    	at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:86)
    	at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
    [...]
    I've readed about aspects aren't getting well proxied, but I haven't been able neither to configure them properly nor finding how to do it. Any help would be greatly appreciated O:-)

    Second issue, is @AfterThrowing well defined (I want to catch all type of Exceptions)?? I'm not very sure

    And last issue, this time regarding AnnotationLoggerInterceptor: that class has more or less the same methods as PackagesLoggerInterceptor but changing the annotations to check for annotated methods or classes, so pointcuts are defined as follows:
    Code:
    @annotation( com.bungee.annotations.Loggeable )
    Does this captures annotated classes and methods or only annotated methods?? I find Spring documentation a little unclear at this point.

    I'm using AspectJ 1.5.3, Spring 2.0.6, Apffuse2.0 (Struts2 + ibatis flavour) and Java6

    Thanks in advance!

  • #2
    Main issue solved

    Hi all,

    found what was going wrong by myself: As noted several -lots of- times on this forum, I had to use proxy-target-class attribute, in order to use our Aspect (also) with Struts2 action classes, as jdk-proxies only work with interfaces.

    Code:
    <aop:aspectj-autoproxy proxy-target-class="true"/>
    The problem was, this bean was declared in an applicationContext file inside an appfuse jar, without this attribute. I was trying to overwrite this bean on our own applicationContext file (which is setted to load afterwards), but it seems that Springs does not overwrite it, hence the error. We've moved all beans declared inside the appfuse jar to our applicationContext file, redeclared autoproxy as noted above, and removed this appfuse's applicationContext file from our list of applicationContext files.

    Regards,
    Michael K.

    Comment

    Working...
    X