Results 1 to 8 of 8

Thread: bean PCD

  1. #1
    Join Date
    Jun 2009
    Posts
    25

    Default bean PCD

    Hi,

    i'm using Spring AOP in one of my projects, and the "bean" pointcut expression keyword is exactly what i'm looking for.

    I have a slight problem though: i would like to enable the aspect for every method returning a MessageI18N object, defined in a "Service(something)Impl" bean

    I tried to define my pointcut that way:

    Code:
    <aop:config>
    	<aop:pointcut 
    		id="services" 
    		expression="bean(Service*Impl) and execution(MessageI18N *.*(..))" 
    	/>
    	<aop:advisor advice-ref="txAdvice" pointcut-ref="services" />
    </aop:config>
    but it didn't work. I also tried with

    Code:
    expression="bean(Service*) and bean(*Impl) and execution(MessageI18N *.*(..))"
    but it didn't work either.

    I get it to work with:

    Code:
    expression="bean(*Impl) and execution(MessageI18N *.*(..))"
    but i would like to have the pointcut as restrictive as possible, which isn't the case with the previous expression, since i lose the "Service" part of the bean name.

    I'm looking for a tutorial about how wildcards work in pointcut expressions but couldn't find one in Spring reference guide :\

    can anyone help me on this one?

    Thanks a lot!

  2. #2
    Join Date
    Jun 2006
    Location
    SF Bay Area, California
    Posts
    524

    Default

    What is the name (not type) of the bean you are trying to match?

    -Ramnivas
    Ramnivas Laddad (Follow me on Twitter)
    AspectJ in Action: Enterprise AOP with Spring Applications (2nd edition). Now available!

  3. #3
    Join Date
    Jun 2009
    Posts
    25

    Default

    Quote Originally Posted by ramnivas View Post
    What is the name (not type) of the bean you are trying to match?

    -Ramnivas
    i don't use autowiring by name, i use autowiring by type ; the classnames of the beans i'm trying to match are:

    ServiceAmiImpl
    ServiceGroupeImpl
    ServicePublicationImpl
    and so on...

    Thanks for your help, by the way

  4. #4
    Join Date
    Jun 2006
    Location
    SF Bay Area, California
    Posts
    524

    Default

    The only thing that matters to the bean() PCD is the name of the bean (and not if you use autowiring by type or name, or no autowiring at all).

    How are your beans declared? Do you use component scanning?

    -Ramnivas
    Ramnivas Laddad (Follow me on Twitter)
    AspectJ in Action: Enterprise AOP with Spring Applications (2nd edition). Now available!

  5. #5
    Join Date
    Jun 2009
    Posts
    25

    Default

    Quote Originally Posted by ramnivas View Post
    The only thing that matters to the bean() PCD is the name of the bean (and not if you use autowiring by type or name, or no autowiring at all).

    How are your beans declared? Do you use component scanning?

    -Ramnivas
    i do. I suppose that with component scanning, the beans names are default names spring generates at startup. I guess that it uses the classname of the bean as its name?
    Last edited by calvino_ind; Jan 1st, 2010 at 10:48 AM.

  6. #6
    Join Date
    Jun 2006
    Location
    SF Bay Area, California
    Posts
    524

    Default

    If you use component scanning the bean name is the simple class name (unless you specify explicit names in @Service, @Repository etc. annotations). If so, your original pointcut should have matched. Do the following two match?
    Code:
    expression="bean(Service*) and execution(MessageI18N *.*(..))"
    (The following you already said to match, but confirm anyway)
    Code:
    expression="bean(*Impl) and execution(MessageI18N *.*(..))"
    Ramnivas Laddad (Follow me on Twitter)
    AspectJ in Action: Enterprise AOP with Spring Applications (2nd edition). Now available!

  7. #7
    Join Date
    Jun 2009
    Posts
    25

    Default

    the first one didn't match, but the second one did

    i thought that it could come from the fact that the bean name generated by Spring used java naming conventions, which means that the bean name wasn't "Service*Impl" but "service*Impl", and I tested the pointcut with this second expression, which solved the problem

    Thanks for your help, ramnivas

  8. #8
    Join Date
    Jun 2006
    Location
    SF Bay Area, California
    Posts
    524

    Default

    Yes, indeed the bean name change the first letter to lowercase. I am glad you have it working now.

    -Ramnivas
    Ramnivas Laddad (Follow me on Twitter)
    AspectJ in Action: Enterprise AOP with Spring Applications (2nd edition). Now available!

Posting Permissions

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