Frage

I am trying to implement AOP in grails. I followed this link .

I created a service and an advice class in src/groovy folder. But unfortunately code is not working for me.below is my code.

package com.app.auth
Class MyDemoService
{
  void findAdviceTest(){
    println"find by is running"
  }
}

AOP code (MyNewAdvice.groovy file in src/groovy )

package com.app.auth;

import org.aspectj.lang.annotation.Aspect
import org.aspectj.lang.annotation.Before
import org.springframework.stereotype.Component

@Aspect
@Component
public class MyNewAdvice
{
  @Before("execution(* com.app.auth.MyDemoService.find*())")
  public void connectBeforeFind(){
    println "aop implemented"
  }
}

Please help.

War es hilfreich?

Lösung

Your code is using the Component annotation. Have you enabled the component scanner in resources.groovy with something like this?…

// grails-app/conf/spring/resources.groovy
beans = {
    xmlns context: 'http://www.springframework.org/schema/context'
    context.'component-scan'( 'base-package' : 'com.app.auth' )
}
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top