Search in sources :

Example 26 with DefaultPointcutAdvisor

use of org.springframework.aop.support.DefaultPointcutAdvisor in project tutorials by eugenp.

the class AopConfiguration method performanceMonitorAdvisor.

@Bean
public Advisor performanceMonitorAdvisor() {
    AspectJExpressionPointcut pointcut = new AspectJExpressionPointcut();
    pointcut.setExpression("org.baeldung.performancemonitor.AopConfiguration.monitor()");
    return new DefaultPointcutAdvisor(pointcut, performanceMonitorInterceptor());
}
Also used : AspectJExpressionPointcut(org.springframework.aop.aspectj.AspectJExpressionPointcut) DefaultPointcutAdvisor(org.springframework.aop.support.DefaultPointcutAdvisor) Bean(org.springframework.context.annotation.Bean)

Example 27 with DefaultPointcutAdvisor

use of org.springframework.aop.support.DefaultPointcutAdvisor in project tutorials by eugenp.

the class AopConfiguration method myPerformanceMonitorAdvisor.

@Bean
public Advisor myPerformanceMonitorAdvisor() {
    AspectJExpressionPointcut pointcut = new AspectJExpressionPointcut();
    pointcut.setExpression("org.baeldung.performancemonitor.AopConfiguration.myMonitor()");
    return new DefaultPointcutAdvisor(pointcut, myPerformanceMonitorInterceptor());
}
Also used : AspectJExpressionPointcut(org.springframework.aop.aspectj.AspectJExpressionPointcut) DefaultPointcutAdvisor(org.springframework.aop.support.DefaultPointcutAdvisor) Bean(org.springframework.context.annotation.Bean)

Example 28 with DefaultPointcutAdvisor

use of org.springframework.aop.support.DefaultPointcutAdvisor in project spring-framework by spring-projects.

the class ConfigurationClassPostProcessorTests method genericsBasedInjectionWithLateGenericsMatchingOnJdkProxy.

@Test
void genericsBasedInjectionWithLateGenericsMatchingOnJdkProxy() {
    beanFactory.registerBeanDefinition("configClass", new RootBeanDefinition(RepositoryConfiguration.class));
    new ConfigurationClassPostProcessor().postProcessBeanFactory(beanFactory);
    DefaultAdvisorAutoProxyCreator autoProxyCreator = new DefaultAdvisorAutoProxyCreator();
    autoProxyCreator.setBeanFactory(beanFactory);
    beanFactory.addBeanPostProcessor(autoProxyCreator);
    beanFactory.registerSingleton("traceInterceptor", new DefaultPointcutAdvisor(new SimpleTraceInterceptor()));
    beanFactory.preInstantiateSingletons();
    String[] beanNames = beanFactory.getBeanNamesForType(RepositoryInterface.class);
    assertThat(beanNames).contains("stringRepo");
    beanNames = beanFactory.getBeanNamesForType(ResolvableType.forClassWithGenerics(RepositoryInterface.class, String.class));
    assertThat(beanNames.length).isEqualTo(1);
    assertThat(beanNames[0]).isEqualTo("stringRepo");
    beanNames = beanFactory.getBeanNamesForType(ResolvableType.forClassWithGenerics(RepositoryInterface.class, String.class));
    assertThat(beanNames.length).isEqualTo(1);
    assertThat(beanNames[0]).isEqualTo("stringRepo");
    assertThat(AopUtils.isJdkDynamicProxy(beanFactory.getBean("stringRepo"))).isTrue();
}
Also used : DefaultAdvisorAutoProxyCreator(org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator) SimpleTraceInterceptor(org.springframework.aop.interceptor.SimpleTraceInterceptor) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) DefaultPointcutAdvisor(org.springframework.aop.support.DefaultPointcutAdvisor) Test(org.junit.jupiter.api.Test)

Example 29 with DefaultPointcutAdvisor

use of org.springframework.aop.support.DefaultPointcutAdvisor in project spring-framework by spring-projects.

the class CallCountingInterceptor method getAdvisedProxy.

private TestBean getAdvisedProxy(String pointcutExpression, CallCountingInterceptor interceptor) {
    TestBean target = new TestBean();
    Pointcut pointcut = getPointcut(pointcutExpression);
    DefaultPointcutAdvisor advisor = new DefaultPointcutAdvisor();
    advisor.setAdvice(interceptor);
    advisor.setPointcut(pointcut);
    ProxyFactory pf = new ProxyFactory();
    pf.setTarget(target);
    pf.addAdvisor(advisor);
    return (TestBean) pf.getProxy();
}
Also used : Pointcut(org.springframework.aop.Pointcut) ITestBean(org.springframework.beans.testfixture.beans.ITestBean) TestBean(org.springframework.beans.testfixture.beans.TestBean) ProxyFactory(org.springframework.aop.framework.ProxyFactory) DefaultPointcutAdvisor(org.springframework.aop.support.DefaultPointcutAdvisor)

Example 30 with DefaultPointcutAdvisor

use of org.springframework.aop.support.DefaultPointcutAdvisor in project spring-framework by spring-projects.

the class AspectJPrecedenceComparatorTests method createSpringAOPBeforeAdvice.

private Advisor createSpringAOPBeforeAdvice(int order) {
    BeforeAdvice advice = new BeforeAdvice() {
    };
    DefaultPointcutAdvisor advisor = new DefaultPointcutAdvisor(this.anyOldPointcut, advice);
    advisor.setOrder(order);
    return advisor;
}
Also used : AspectJMethodBeforeAdvice(org.springframework.aop.aspectj.AspectJMethodBeforeAdvice) BeforeAdvice(org.springframework.aop.BeforeAdvice) DefaultPointcutAdvisor(org.springframework.aop.support.DefaultPointcutAdvisor)

Aggregations

DefaultPointcutAdvisor (org.springframework.aop.support.DefaultPointcutAdvisor)45 Test (org.junit.jupiter.api.Test)29 DefaultAdvisorAutoProxyCreator (org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator)16 SimpleTraceInterceptor (org.springframework.aop.interceptor.SimpleTraceInterceptor)16 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)14 ITestBean (org.springframework.beans.testfixture.beans.ITestBean)12 NopInterceptor (org.springframework.aop.testfixture.interceptor.NopInterceptor)11 TestBean (org.springframework.beans.testfixture.beans.TestBean)11 Advisor (org.springframework.aop.Advisor)8 DefaultIntroductionAdvisor (org.springframework.aop.support.DefaultIntroductionAdvisor)7 CountingBeforeAdvice (org.springframework.aop.testfixture.advice.CountingBeforeAdvice)7 SerializableNopInterceptor (org.springframework.aop.testfixture.interceptor.SerializableNopInterceptor)7 AspectJExpressionPointcut (org.springframework.aop.aspectj.AspectJExpressionPointcut)6 GenericWebApplicationContext (org.springframework.web.context.support.GenericWebApplicationContext)5 Pointcut (org.springframework.aop.Pointcut)4 ClassPathResource (org.springframework.core.io.ClassPathResource)4 ResourceScriptSource (org.springframework.scripting.support.ResourceScriptSource)4 Test (org.junit.Test)3 NameMatchMethodPointcut (org.springframework.aop.support.NameMatchMethodPointcut)3 StaticMethodMatcherPointcutAdvisor (org.springframework.aop.support.StaticMethodMatcherPointcutAdvisor)3