Announcement Announcement Module
Collapse
No announcement yet.
aspectj-autoproxy + annotation type error Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • aspectj-autoproxy + annotation type error

    Hi everyone,
    My first post here

    I am having a situation that i can't solve. I am new to Spring but i think this should be simple.
    I am trying do to some "Aspect" but it doesn't work. The only "visible" thing i got is an error:
    Code:
    java.lang.IllegalArgumentException: error Type referred to is not an annotation type: com$business$commons$annotation$LoggerAnnotation
    when adding the line
    Code:
    <aop:aspectj-autoproxy />
    to my context xml file.

    So my code looks like this:

    Annotation:
    Code:
    package com.business.commons.postprocess.annotation;
    
    import java.lang.annotation.ElementType;
    import java.lang.annotation.Retention;
    import java.lang.annotation.RetentionPolicy;
    import java.lang.annotation.Target;
    
    /**
     *
     * @author gesf
     */
    @Target({ElementType.METHOD })
    @Retention(RetentionPolicy.RUNTIME)
    public @interface LoggerAnnotation {
    }
    Aspect:
    Code:
    package com.business.commons.postprocess.aspect;
    
    import org.aspectj.lang.JoinPoint;
    import org.aspectj.lang.annotation.AfterReturning;
    import org.aspectj.lang.annotation.Aspect;
    import org.springframework.stereotype.Component;
    
    /**
     *
     * @author gesf
     */
    @Component
    @Aspect
    public class LoggerAspect {
        
        /**
         * My Aspect.
         * @param joinPoint JoinPoint.
         * @param response Object.
         * @return nothing Object.
         */
        @AfterReturning(pointcut = "@annotation(com.business.commons.annotation.LoggerAnnotation)", returning = "response")
        public Object whenAnnotatedMethodIsInvoked(final JoinPoint joinPoint, final Object response) {
    
            System.out.print("testing!");
            return "testing";
            
        }       
        
    }
    Controller (wanted advised):
    Code:
    /**
         * mapping request for page.
         * 
         * @param request HttpServletRequest.
         * @return nothing Object.
         */
        @LoggerAnnotation
        @RequestMapping(value = "/page", method = RequestMethod.GET)
        @ResponseBody
        public String getPageRequest(final HttpServletRequest request) {
            // do something
            return "ok";
        }
    Context .xml (config):
    Code:
    <?xml version="1.0" encoding="windows-1252"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xmlns:context="http://www.springframework.org/schema/context
            xmlns:aop="http://www.springframework.org/schema/aop"
            xsi:schemaLocation="http://www.springframework.org/schema/context
                                  http://www.springframework.org/schema/context/spring-context-2.5.xsd
                                  http://www.springframework.org/schema/beans
                                    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
                                    http://www.springframework.org/schema/aop
                                    http://www.springframework.org/schema/aop/spring-aop-3.0.xsd ">
     
        <context:component-scan base-package="com.business.commons.postprocess.aspect"/>
        <context:component-scan base-package="com.business.commons.postprocess.annotation"/>
    
        <aop:aspectj-autoproxy />
        
    </beans>
    (edited: erroneous calls above were already fixed to 3.1, but the same happens)

    And the error in the top is what i get when adding the auto proxy line. Without it nothing happens, still i can build the application. I have tried other pointcut expressions, but i think that's not the problem. The Spring release being used is 3.1.1 and / 3.1.0 for security (just in case).

    Any ideas on how to solve this !?
    Thanks in advance!

    Cheers,
    gesf
    Last edited by gesf; Jul 24th, 2012, 10:13 AM.

  • #2
    Instead of
    @AfterReturning(pointcut = "@annotation(com.business.commons.annotation.Logge rAnnotation)", returning = "response")
    public Object whenAnnotatedMethodIsInvoked(final JoinPoint joinPoint, final Object response) {

    try

    @AfterReturning(pointcut = "@annotation(LoggerAnnotation)", returning = "response")
    public Object whenAnnotatedMethodIsInvoked(final JoinPoint joinPoint, final Object response) {

    Comment


    • #3
      Hey debabratp! Thanks for your reply.
      Well... the error is exactly the same with that change!
      Any other ideas ?
      Cheers

      Comment


      • #4
        Originally posted by gesf View Post
        Hey debabratp! Thanks for your reply.
        Well... the error is exactly the same with that change!
        Any other ideas ?
        Cheers
        In your @annotation declaration i found the package name is wrong, it must be com.business.commons.postprocess.annotation.Logger Annotation.

        Are you using Java 7?

        Comment

        Working...
        X