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:when adding the lineCode:java.lang.IllegalArgumentException: error Type referred to is not an annotation type: com$business$commons$annotation$LoggerAnnotationto my context xml file.Code:<aop:aspectj-autoproxy />
So my code looks like this:
Annotation:Aspect: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 { }Controller (wanted advised):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"; } }Context .xml (config):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"; }(edited: erroneous calls above were already fixed to 3.1, but the same happens)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>
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



Reply With Quote
