Question

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.

Was it helpful?

Solution

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' )
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top