Results 1 to 7 of 7

Thread: @Configurable @Aspect - AspectJ aspect configured by spring

  1. #1
    Join Date
    Apr 2006
    Posts
    12

    Default @Configurable @Aspect - AspectJ aspect configured by spring

    Hello is this a way how I can configure aspect witch spring?

    I have this aspect:
    Code:
    @Aspect
    @Configurable
    public class TempletAspect {
    
      /** Describe templet here. */
      @Autowired
      @Qualifier("templet")
      private ITemplet templet;
    
      /** Get the <code>Templet</code> value.
       * @return a value
       */
      public final ITemplet getTemplet() {
        return templet;
      }
    
      /** Set the <code>Templet</code> value.
       * @param newTemplet The new Templet value.
       */
      public final void setTemplet(final ITemplet newTemplet) {
        this.templet = newTemplet;
      }
    
      @Around("target(cz.apnetis.web.INeedTemplet) && call(* *.getTemplet())")
      public final Object setTempletToController(final ProceedingJoinPoint
                                                 thisJoinPoint) {
        System.out.println("ASPECT IS CALLL --------------------");
        return getTemplet();
      }
    }
    Aspect is call but propertie ITemplet isn't set and this exception raise:
    Code:
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cz.apnetis.web.support.TempletAspect': Autowiring of fields failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private cz.apnetis.web.ITemplet cz.apnetis.web.support.TempletAspect.templet; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No unique bean of type [cz.apnetis.web.ITemplet] is defined: Unsatisfied dependency of type [interface cz.apnetis.web.ITemplet]: expected at least 1 matching bean
    But I have templet which implements ITemplet in my spring context.

    Its there a way to mixing AspectJ and Spring in one aspect?
    ------------------------------------------------------------
    I use XEmacs + JDEE, Spring, Hibernate and special benzin's fork of English.

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

    Default

    Why do you want your bean to be @Configurable?! Do you plan on creating new instances of the TempletAspect in your code? At least that is what the @Configurable is used for, next to that I don't see the added value on an @Aspect bean. So remove it.

    Next to that please post your whole stacktrace so that we can see the full message. Make sure that there is a bean of type ITemplet with the name 'templet' in your configuration.
    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
    Jun 2006
    Location
    The Netherlands
    Posts
    13,624

    Default

    Why do you want your bean to be @Configurable?! Do you plan on creating new instances of the TempletAspect in your code? At least that is what the @Configurable is used for, next to that I don't see the added value on an @Aspect bean. So remove it.

    Next to that please post your whole stacktrace so that we can see the full message. Make sure that there is a bean of type ITemplet with the name 'templet' in your configuration.
    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

  4. #4
    Join Date
    Apr 2006
    Posts
    12

    Default

    Quote Originally Posted by mdeinum View Post
    Why do you want your bean to be @Configurable?! Do you plan on creating new instances of the TempletAspect in your code? At least that is what the @Configurable is used for, next to that I don't see the added value on an @Aspect bean. So remove it.

    Next to that please post your whole stacktrace so that we can see the full message. Make sure that there is a bean of type ITemplet with the name 'templet' in your configuration.
    Now I use aspects which configure my Controller (web controller), and add templet (which is wrapper, but it's hidden) to all Controller which is in application.

    When I Use spring configured aspect I can write this:
    Code:
    <bean id="templetAspect" class="cz.ap.....TempletAspect">
      <property name="parametr" ref="someBean" />
    </bean>
    Yes, it's spring configurable aspect. But when I use aspect configurable bean, then I cannot use configurable aspect. Because of @Configurable and @Aspect in one bean cannot be used.

    Yes, it's another way. To anotatte all controller with @Configurable, and templet which is set by templet aspect will be set directly by spring. But when I inherit from class which have some property anotated with @Autowire(required = true), then i cannot use spring context, to set this properties.

    On example, when I anotate witch @Configure class which inherite from HiberanteSuport then I must have SessionFactory and HibernateProperty set by annotation, not only from spring context.

    Yes, it's conflict between spring configurable and aspectj AOP. I need spring configurable Aspect. But I want use my aspect in all aplication, not only in bean which create spring. Because of I want make aspect, which can be configured from spring.
    ------------------------------------------------------------
    I use XEmacs + JDEE, Spring, Hibernate and special benzin's fork of English.

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

    Default

    Again WHY does your Aspect have to be @Configurable??? I strongly suggest you read the chapter about @Configurable and also the chapter about annotation based configuration. For annotation based configuration yuo don't need the @Configurable.
    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

  6. #6
    Join Date
    Apr 2006
    Posts
    12

    Default

    Quote Originally Posted by mdeinum View Post
    Again WHY does your Aspect have to be @Configurable??? I strongly suggest you read the chapter about @Configurable and also the chapter about annotation based configuration. For annotation based configuration yuo don't need the @Configurable.
    Yes I needn't use @Configurable but I need @Autowired, becouse I want set parameter to annotation. But I don't know if compiled anntotation is call as new instance of class, or is add around the method, and defacto is wired to target class and no instance of aspect class is create.
    ------------------------------------------------------------
    I use XEmacs + JDEE, Spring, Hibernate and special benzin's fork of English.

  7. #7
    Join Date
    Jul 2009
    Posts
    1

    Talking Workaround

    Quote Originally Posted by benzin View Post
    Its there a way to mixing AspectJ and Spring in one aspect?
    Hi, I solved this question using CTW (Compile-time Weaving) on the Annotation @Configure. I followed the Chris Searle Blog entry (http://www.chrissearle.org/blog/tech...ng_using_maven) about CTW using Maven.

    Added this entry on maven:

    Code:
                <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>aspectj-maven-plugin</artifactId>
                    <configuration>
                        <complianceLevel>1.5</complianceLevel>
                        <aspectLibraries>
                            <aspectLibrary>
                                <groupId>org.springframework</groupId>
                                <artifactId>spring-aspects</artifactId>
                            </aspectLibrary>
                        </aspectLibraries>
                    </configuration>
                    <executions>
                        <execution>
                            <goals>
                                <goal>compile</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
    And Kept the Load Time Weaving for the AspectJ Annotation.

    BTW, do you really need this? I guess Marten Deinum is right about it.
    Last edited by RRantz; Jul 21st, 2009 at 09:34 PM. Reason: grammar errors

Posting Permissions

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