Java Code Examples for org.springframework.aop.support.annotation.AnnotationMatchingPointcut

The following examples show how to use org.springframework.aop.support.annotation.AnnotationMatchingPointcut. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
/**
 * Create a new PersistenceExceptionTranslationAdvisor.
 *
 * @param beanFactory              the ListableBeanFactory to obtaining all
 *                                 PersistenceExceptionTranslators from
 * @param repositoryAnnotationType the annotation type to check for
 */
ReactivePersistenceExceptionTranslationAdvisor(ListableBeanFactory beanFactory,
	Class<? extends Annotation> repositoryAnnotationType) {

	this.advice = new ReactivePersistenceExceptionTranslationInterceptor(beanFactory);
	this.pointcut = new AnnotationMatchingPointcut(repositoryAnnotationType, true) {
		@Override
		public MethodMatcher getMethodMatcher() {
			return new StaticMethodMatcher() {

				@Override public boolean matches(Method method, Class<?> targetClass) {
					Class<?> returnType = method.getReturnType();
					return returnType == Mono.class || returnType == Flux.class;
				}
			};
		}
	};
}
 
Example 2
Source Project: spring-analysis-note   Source File: CglibProxyControllerTests.java    License: MIT License 6 votes vote down vote up
@SuppressWarnings("serial")
private void initServlet(final Class<?> controllerClass) throws ServletException {
	servlet = new DispatcherServlet() {
		@Override
		protected WebApplicationContext createWebApplicationContext(@Nullable WebApplicationContext parent) {
			GenericWebApplicationContext wac = new GenericWebApplicationContext();
			wac.registerBeanDefinition("controller", new RootBeanDefinition(controllerClass));
			DefaultAdvisorAutoProxyCreator autoProxyCreator = new DefaultAdvisorAutoProxyCreator();
			autoProxyCreator.setProxyTargetClass(true);
			autoProxyCreator.setBeanFactory(wac.getBeanFactory());
			wac.getBeanFactory().addBeanPostProcessor(autoProxyCreator);
			Pointcut pointcut = new AnnotationMatchingPointcut(Controller.class);
			DefaultPointcutAdvisor advisor = new DefaultPointcutAdvisor(pointcut, new SimpleTraceInterceptor(true));
			wac.getBeanFactory().registerSingleton("advisor", advisor);
			wac.refresh();
			return wac;
		}
	};
	servlet.init(new MockServletConfig());
}
 
Example 3
Source Project: java-technology-stack   Source File: CglibProxyControllerTests.java    License: MIT License 6 votes vote down vote up
@SuppressWarnings("serial")
private void initServlet(final Class<?> controllerClass) throws ServletException {
	servlet = new DispatcherServlet() {
		@Override
		protected WebApplicationContext createWebApplicationContext(@Nullable WebApplicationContext parent) {
			GenericWebApplicationContext wac = new GenericWebApplicationContext();
			wac.registerBeanDefinition("controller", new RootBeanDefinition(controllerClass));
			DefaultAdvisorAutoProxyCreator autoProxyCreator = new DefaultAdvisorAutoProxyCreator();
			autoProxyCreator.setProxyTargetClass(true);
			autoProxyCreator.setBeanFactory(wac.getBeanFactory());
			wac.getBeanFactory().addBeanPostProcessor(autoProxyCreator);
			Pointcut pointcut = new AnnotationMatchingPointcut(Controller.class);
			DefaultPointcutAdvisor advisor = new DefaultPointcutAdvisor(pointcut, new SimpleTraceInterceptor(true));
			wac.getBeanFactory().registerSingleton("advisor", advisor);
			wac.refresh();
			return wac;
		}
	};
	servlet.init(new MockServletConfig());
}
 
Example 4
Source Project: beihu-boot   Source File: ApiBootDataSourceSwitchAdvisor.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * build pointcut instance
 */
private Pointcut buildPointcut() {
    // class
    Pointcut cpc = new AnnotationMatchingPointcut(DataSourceSwitch.class, true);
    // method
    Pointcut mpc = AnnotationMatchingPointcut.forMethodAnnotation(DataSourceSwitch.class);

    //union
    ComposablePointcut pointcut = new ComposablePointcut(cpc);
    return pointcut.union(mpc);
}
 
Example 5
/**
 * Create a new PersistenceExceptionTranslationAdvisor.
 * @param persistenceExceptionTranslator the PersistenceExceptionTranslator to use
 * @param repositoryAnnotationType the annotation type to check for
 */
public PersistenceExceptionTranslationAdvisor(
		PersistenceExceptionTranslator persistenceExceptionTranslator,
		Class<? extends Annotation> repositoryAnnotationType) {

	this.advice = new PersistenceExceptionTranslationInterceptor(persistenceExceptionTranslator);
	this.pointcut = new AnnotationMatchingPointcut(repositoryAnnotationType, true);
}
 
Example 6
/**
 * Create a new PersistenceExceptionTranslationAdvisor.
 * @param beanFactory the ListableBeanFactory to obtaining all
 * PersistenceExceptionTranslators from
 * @param repositoryAnnotationType the annotation type to check for
 */
PersistenceExceptionTranslationAdvisor(
		ListableBeanFactory beanFactory, Class<? extends Annotation> repositoryAnnotationType) {

	this.advice = new PersistenceExceptionTranslationInterceptor(beanFactory);
	this.pointcut = new AnnotationMatchingPointcut(repositoryAnnotationType, true);
}
 
Example 7
/**
 * Create a new PersistenceExceptionTranslationAdvisor.
 * @param persistenceExceptionTranslator the PersistenceExceptionTranslator to use
 * @param repositoryAnnotationType the annotation type to check for
 */
public PersistenceExceptionTranslationAdvisor(
		PersistenceExceptionTranslator persistenceExceptionTranslator,
		Class<? extends Annotation> repositoryAnnotationType) {

	this.advice = new PersistenceExceptionTranslationInterceptor(persistenceExceptionTranslator);
	this.pointcut = new AnnotationMatchingPointcut(repositoryAnnotationType, true);
}
 
Example 8
/**
 * Create a new PersistenceExceptionTranslationAdvisor.
 * @param beanFactory the ListableBeanFactory to obtaining all
 * PersistenceExceptionTranslators from
 * @param repositoryAnnotationType the annotation type to check for
 */
PersistenceExceptionTranslationAdvisor(
		ListableBeanFactory beanFactory, Class<? extends Annotation> repositoryAnnotationType) {

	this.advice = new PersistenceExceptionTranslationInterceptor(beanFactory);
	this.pointcut = new AnnotationMatchingPointcut(repositoryAnnotationType, true);
}
 
Example 9
Source Project: api-boot   Source File: ApiBootDataSourceSwitchAdvisor.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * build pointcut instance
 * use {@link DataSourceSwitch} as a {@link Pointcut}
 * scope:
 * 1. {@link DataSourceSwitch} on the class
 * 2. {@link DataSourceSwitch} on the method
 */
private Pointcut buildPointcut() {
    // class
    Pointcut cpc = new AnnotationMatchingPointcut(DataSourceSwitch.class, true);
    // method
    Pointcut mpc = AnnotationMatchingPointcut.forMethodAnnotation(DataSourceSwitch.class);

    //union
    ComposablePointcut pointcut = new ComposablePointcut(cpc);
    return pointcut.union(mpc);
}
 
Example 10
Source Project: distributed-lock   Source File: LockBeanPostProcessor.java    License: MIT License 5 votes vote down vote up
@Override
public void afterPropertiesSet() {
  final var pointcut = new AnnotationMatchingPointcut(null, Locked.class, true);
  final var interceptor = new LockMethodInterceptor(keyGenerator, lockTypeResolver, intervalConverter, retriableLockFactory, taskScheduler);

  this.advisor = new DefaultPointcutAdvisor(pointcut, interceptor);
}
 
Example 11
/**
 * Create a new PersistenceExceptionTranslationAdvisor.
 * @param persistenceExceptionTranslator the PersistenceExceptionTranslator to use
 * @param repositoryAnnotationType the annotation type to check for
 */
public PersistenceExceptionTranslationAdvisor(
		PersistenceExceptionTranslator persistenceExceptionTranslator,
		Class<? extends Annotation> repositoryAnnotationType) {

	this.advice = new PersistenceExceptionTranslationInterceptor(persistenceExceptionTranslator);
	this.pointcut = new AnnotationMatchingPointcut(repositoryAnnotationType, true);
}
 
Example 12
/**
 * Create a new PersistenceExceptionTranslationAdvisor.
 * @param beanFactory the ListableBeanFactory to obtaining all
 * PersistenceExceptionTranslators from
 * @param repositoryAnnotationType the annotation type to check for
 */
PersistenceExceptionTranslationAdvisor(
		ListableBeanFactory beanFactory, Class<? extends Annotation> repositoryAnnotationType) {

	this.advice = new PersistenceExceptionTranslationInterceptor(beanFactory);
	this.pointcut = new AnnotationMatchingPointcut(repositoryAnnotationType, true);
}
 
Example 13
/**
 * Calculate a pointcut for the given async annotation types, if any.
 * @param asyncAnnotationTypes the async annotation types to introspect
 * @return the applicable Pointcut object, or {@code null} if none
 */
protected Pointcut buildPointcut(Set<Class<? extends Annotation>> asyncAnnotationTypes) {
	ComposablePointcut result = null;
	for (Class<? extends Annotation> asyncAnnotationType : asyncAnnotationTypes) {
		Pointcut cpc = new AnnotationMatchingPointcut(asyncAnnotationType, true);
		Pointcut mpc = AnnotationMatchingPointcut.forMethodAnnotation(asyncAnnotationType);
		if (result == null) {
			result = new ComposablePointcut(cpc).union(mpc);
		}
		else {
			result.union(cpc).union(mpc);
		}
	}
	return result;
}
 
Example 14
/**
 * Create a new PersistenceExceptionTranslationAdvisor.
 * @param persistenceExceptionTranslator the PersistenceExceptionTranslator to use
 * @param repositoryAnnotationType the annotation type to check for
 */
public PersistenceExceptionTranslationAdvisor(
		PersistenceExceptionTranslator persistenceExceptionTranslator,
		Class<? extends Annotation> repositoryAnnotationType) {

	this.advice = new PersistenceExceptionTranslationInterceptor(persistenceExceptionTranslator);
	this.pointcut = new AnnotationMatchingPointcut(repositoryAnnotationType, true);
}
 
Example 15
/**
 * Create a new PersistenceExceptionTranslationAdvisor.
 * @param beanFactory the ListableBeanFactory to obtaining all
 * PersistenceExceptionTranslators from
 * @param repositoryAnnotationType the annotation type to check for
 */
PersistenceExceptionTranslationAdvisor(
		ListableBeanFactory beanFactory, Class<? extends Annotation> repositoryAnnotationType) {

	this.advice = new PersistenceExceptionTranslationInterceptor(beanFactory);
	this.pointcut = new AnnotationMatchingPointcut(repositoryAnnotationType, true);
}
 
Example 16
Source Project: cat-boot   Source File: JavaMelodyAutoConfiguration.java    License: Apache License 2.0 5 votes vote down vote up
@ConditionalOnProperty(name = "javamelody.enableSpringServiceMonitoring", havingValue = "true")
@Bean
public MonitoringSpringAdvisor springServiceMonitoringAdvisor() {
    final MonitoringSpringAdvisor interceptor = new MonitoringSpringAdvisor();
    interceptor.setPointcut(new AnnotationMatchingPointcut(Service.class));
    return interceptor;
}
 
Example 17
Source Project: cat-boot   Source File: JavaMelodyAutoConfiguration.java    License: Apache License 2.0 5 votes vote down vote up
@ConditionalOnProperty(name = "javamelody.enableSpringControllerMonitoring", havingValue = "true")
@Bean
public MonitoringSpringAdvisor springControllerMonitoringAdvisor() {
    final MonitoringSpringAdvisor interceptor = new MonitoringSpringAdvisor();
    interceptor.setPointcut(new AnnotationMatchingPointcut(Controller.class));
    return interceptor;
}
 
Example 18
ShardingTransactionTypeAdvisor() {
    Pointcut classPointcut = new ComposablePointcut(AnnotationMatchingPointcut.forClassAnnotation(ShardingTransactionType.class));
    Pointcut methodPointcut = new ComposablePointcut(AnnotationMatchingPointcut.forMethodAnnotation(ShardingTransactionType.class));
    transactionTypePointcut = new ComposablePointcut(classPointcut).union(methodPointcut);
    transactionTypeInterceptor = new ShardingTransactionTypeInterceptor();
    setOrder(Ordered.LOWEST_PRECEDENCE - 1);
}
 
Example 19
Source Project: cuba   Source File: CubaMethodValidationPostProcessor.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void afterPropertiesSet() {
    Pointcut pointcut = new AnnotationMatchingPointcut(Service.class, Validated.class, true);
    DefaultPointcutAdvisor advisor = new DefaultPointcutAdvisor(pointcut, createMethodValidationAdvice(this.beanValidation));
    advisor.setOrder(2);
    this.advisor = advisor;
}
 
Example 20
Source Project: ShedLock   Source File: MethodProxyScheduledLockAdvisor.java    License: Apache License 2.0 5 votes vote down vote up
@NonNull
private static AnnotationMatchingPointcut methodPointcutFor(Class<? extends Annotation> methodAnnotationType) {
    return new AnnotationMatchingPointcut(
        null,
        methodAnnotationType,
        true
    );
}
 
Example 21
Source Project: javamelody   Source File: JavaMelodyAutoConfiguration.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Monitoring of beans having the {@link Service} annotation.
 * @return MonitoringSpringAdvisor
 */
@Bean
@ConditionalOnProperty(prefix = JavaMelodyConfigurationProperties.PREFIX, name = "spring-monitoring-enabled", matchIfMissing = true)
public MonitoringSpringAdvisor monitoringSpringServiceAdvisor() {
	return createMonitoringSpringAdvisorWithExclusions(
			new AnnotationMatchingPointcut(Service.class),
			monitoredWithSpringAnnotationPointcut, asyncAnnotationPointcut,
			scheduledAnnotationPointcut);
}
 
Example 22
Source Project: javamelody   Source File: JavaMelodyAutoConfiguration.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Monitoring of beans having the {@link Controller} annotation.
 * @return MonitoringSpringAdvisor
 */
@Bean
@ConditionalOnProperty(prefix = JavaMelodyConfigurationProperties.PREFIX, name = "spring-monitoring-enabled", matchIfMissing = true)
public MonitoringSpringAdvisor monitoringSpringControllerAdvisor() {
	return createMonitoringSpringAdvisorWithExclusions(
			new AnnotationMatchingPointcut(Controller.class),
			monitoredWithSpringAnnotationPointcut, asyncAnnotationPointcut,
			scheduledAnnotationPointcut);
}
 
Example 23
Source Project: javamelody   Source File: JavaMelodyAutoConfiguration.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Monitoring of beans having the {@link RestController} annotation.
 * @return MonitoringSpringAdvisor
 */
@Bean
@ConditionalOnProperty(prefix = JavaMelodyConfigurationProperties.PREFIX, name = "spring-monitoring-enabled", matchIfMissing = true)
public MonitoringSpringAdvisor monitoringSpringRestControllerAdvisor() {
	return createMonitoringSpringAdvisorWithExclusions(
			new AnnotationMatchingPointcut(RestController.class),
			monitoredWithSpringAnnotationPointcut, asyncAnnotationPointcut,
			scheduledAnnotationPointcut);
}
 
Example 24
@Override
public void afterPropertiesSet() {
	Pointcut pointcut = new AnnotationMatchingPointcut(this.validatedAnnotationType, true);
	this.advisor = new DefaultPointcutAdvisor(pointcut, createMethodValidationAdvice(this.validator));
}
 
Example 25
Source Project: easy-sentinel   Source File: AbstractRegistryCenter.java    License: Apache License 2.0 4 votes vote down vote up
@PostConstruct
public void initMethodMater() {
    methodMatcher = AnnotationMatchingPointcut.forMethodAnnotation(EasySentinel.class).getMethodMatcher();
}
 
Example 26
@Override
public void afterPropertiesSet() {
	Pointcut pointcut = new AnnotationMatchingPointcut(this.validatedAnnotationType, true);
	this.advisor = new DefaultPointcutAdvisor(pointcut, createMethodValidationAdvice(this.validator));
}
 
Example 27
Source Project: api-boot   Source File: ApiBootResourceLoadAdvisor.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * build pointcut instance
 */
private Pointcut buildPointcut() {
    // method
    Pointcut mpc = AnnotationMatchingPointcut.forMethodAnnotation(ResourceLoad.class);
    return new ComposablePointcut(mpc);
}
 
Example 28
/**
 * build pointcut instance
 */
private Pointcut buildPointcut() {
    // method
    Pointcut mpc = AnnotationMatchingPointcut.forMethodAnnotation(MessagePushSwitch.class);
    return mpc;
}
 
Example 29
Source Project: common-project   Source File: MethodLockConfiguration.java    License: Apache License 2.0 4 votes vote down vote up
@Bean
public Pointcut pointcut(){
    return new AnnotationMatchingPointcut(null,MethodLock.class);
}
 
Example 30
@Override
public void afterPropertiesSet() {
	Pointcut pointcut = new AnnotationMatchingPointcut(this.validatedAnnotationType, true);
	this.advisor = new DefaultPointcutAdvisor(pointcut, createMethodValidationAdvice(this.validator));
}