If you don't want to use any xml code at all, you can create a separate Java configuration class for aspects
@Configuration @EnableAspectJAutoProxy @ComponentScan(basePackages = "com.myAspects") public class AspectConfig {
And import the above configuration class into your main AppConfig class
@Configuration @EnableWebMvc @Import({ AspectConfig.class }) @ComponentScan(basePackages = { "pkg1", "pkg2", "pkg3" }) public class AppConfiguration extends WebMvcConfigurationSupport {
Now create your beans aspect
import com.myAspects; @Component @Aspect public class LoggingAspect { @Before("execution(* com.service.*.*(..))") public void logBefore(){ System.out.println("before advice called"); } @After("execution(* com.service.*.*(..))") public void logAfter(){ System.out.println("after advice called"); } }
You can use pointcut along with annotation of recommendations, as shown above.
Anil agrawal
source share