Announcement Announcement Module
No announcement yet.
NoSuchMethodException when Aspecting classes Page Title Module
Move Remove Collapse
Conversation Detail Module
  • 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):
    <beans xmlns="" xmlns:xsi=""
           xmlns:aop="" xmlns:tx=""
        <!-- =================================================================== -->
        <!-- AOP: Configuration and Aspects                                      -->
        <!-- =================================================================== -->
            <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"/>
        <!-- Enable @Transactional support -->
        <!-- Fix bug in Spring 2.0.6: -->
        <bean class="org.springframework.transaction.aspectj.AnnotationTransactionAspect" factory-method="aspectOf" dependency-check="none" lazy-init="false">
            <property name="transactionManager" ref="transactionManager"/>
        <!-- Enable @AspectJ support -->
        <!-- Enable @Configured support -->
        <tx:advice id="txAdvice">
                <!-- Read-only commented out to make things easier for end-users -->
                <!-- -->
                <!--tx:method name="get*" read-only="true"/-->
                <tx:method name="*"/>
        <tx:advice id="userManagerTxAdvice">
                <tx:method name="save*" rollback-for="UserExistsException"/>
        <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:

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

    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:

    java.lang.NoSuchMethodException: $Proxy361.initHome()
    	at java.lang.Class.getMethod(
    	at org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.getActionMethod(
    	at org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(
    	at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(
    	at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(
    	at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(
    	at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(
    	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(
    	at com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(
    	at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(
    	at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(
    	at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(
    	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(
    	at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(
    	at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(
    	at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(
    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:
    @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.

    <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.

    Michael K.