Announcement Announcement Module
Collapse
No announcement yet.
bean PCD Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    What is the name (not type) of the bean you are trying to match?

    -Ramnivas

    Comment


    • #3
      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

      Comment


      • #4
        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

        Comment


        • #5
          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, 11:48 AM.

          Comment


          • #6
            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 *.*(..))"

            Comment


            • #7
              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

              Comment


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

                -Ramnivas

                Comment

                Working...
                X