Results 1 to 3 of 3

Thread: Proxy created for beans that do not match the pointcut expression

  1. #1
    Join Date
    Aug 2011
    Posts
    20

    Default Proxy created for beans that do not match the pointcut expression

    Hi,

    I have following AOP configuration:

    Code:
    	<aop:config>
    		<aop:aspect id="operatorAuditAspect" ref="operatorAPIAuditor">
    			<aop:pointcut id="auditedOperation" expression="within(com.abc..*) &amp;&amp; (@target(com.abc.Audited) || @annotation(com.abc.Audited))" />
    			<aop:after pointcut-ref="auditedOperation" method="doAudit" />
    		</aop:aspect>
    	</aop:config>
    This works OK, the advice is executed for all beans in package com.abc.. with @Audited annotation. However, it seems that ALL beans with types in package com.abc are now proxied, which results in exceptions when I want to inject beans with concrete types.

    e.g.

    No matching bean of type [com.abc.Foo] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency.

    Is this normal?

  2. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,624

    Default

    Which is correct and this has to do with your pointcut expression. It consists of a static part and part that is checked at runtime. The within is the static part, for this match proxies are created (basically everything in the package). The @target and @annotation are checked at runtime.

    I suggest a read of the AspectJ reference guide or the excellent AspectJ in Action (2nd edition).
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  3. #3
    Join Date
    Aug 2011
    Posts
    20

    Default

    Thanks, I got it working by changing @target to @within.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •