本文整理汇总了Java中org.springframework.aop.aspectj.AspectJExpressionPointcut类的典型用法代码示例。如果您正苦于以下问题:Java AspectJExpressionPointcut类的具体用法?Java AspectJExpressionPointcut怎么用?Java AspectJExpressionPointcut使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
AspectJExpressionPointcut类属于org.springframework.aop.aspectj包,在下文中一共展示了AspectJExpressionPointcut类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: defaultPointcutAdvisor
import org.springframework.aop.aspectj.AspectJExpressionPointcut; //导入依赖的package包/类
/**
* 织入
*/
@Bean
public DefaultPointcutAdvisor defaultPointcutAdvisor(TransactionInterceptor interceptor) {
// 切入点
AspectJExpressionPointcut expression = new AspectJExpressionPointcut();
expression.setExpression("execution(* org.sj.alexa.service.tx.I*Service.*(..))");
return new DefaultPointcutAdvisor(expression, interceptor);
}
示例2: testPerTarget
import org.springframework.aop.aspectj.AspectJExpressionPointcut; //导入依赖的package包/类
@Test
public void testPerTarget() throws SecurityException, NoSuchMethodException {
AspectJExpressionPointcut ajexp = new AspectJExpressionPointcut();
ajexp.setExpression(AspectJExpressionPointcutTests.MATCH_ALL_METHODS);
InstantiationModelAwarePointcutAdvisorImpl ajpa = new InstantiationModelAwarePointcutAdvisorImpl(af, ajexp,
new SingletonMetadataAwareAspectInstanceFactory(new PerTargetAspect(),"someBean"), null, 1, "someBean");
assertNotSame(Pointcut.TRUE, ajpa.getAspectMetadata().getPerClausePointcut());
assertTrue(ajpa.getAspectMetadata().getPerClausePointcut() instanceof AspectJExpressionPointcut);
assertTrue(ajpa.isPerInstance());
assertTrue(ajpa.getAspectMetadata().getPerClausePointcut().getClassFilter().matches(TestBean.class));
assertFalse(ajpa.getAspectMetadata().getPerClausePointcut().getMethodMatcher().matches(
TestBean.class.getMethod("getAge", (Class[]) null),
TestBean.class));
assertTrue(ajpa.getAspectMetadata().getPerClausePointcut().getMethodMatcher().matches(
TestBean.class.getMethod("getSpouse", (Class[]) null),
TestBean.class));
}
示例3: packageTraceAdvisor
import org.springframework.aop.aspectj.AspectJExpressionPointcut; //导入依赖的package包/类
@Bean
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
public Advisor packageTraceAdvisor() {
ComposablePointcut resultPointcut = new ComposablePointcut();
{
List<String> basePackages = findBasePackages();
String pointcutExpression = makeExpression(basePackages);
AspectJExpressionPointcut packagePointcut = new AspectJExpressionPointcut();
log.info("Include package Pointcut expression : {}", pointcutExpression);
packagePointcut.setExpression(pointcutExpression);
resultPointcut.intersection((Pointcut) packagePointcut);
}
String excludeAnnotation = buildExcludeAnnotation();
log.info("Exclude Annotation Pointcut expression : {}", excludeAnnotation);
AspectJExpressionPointcut basePointcut = new AspectJExpressionPointcut();
basePointcut.setExpression(excludeAnnotation);
resultPointcut.intersection((Pointcut) basePointcut);
DefaultPointcutAdvisor pointcutAdvisor = new DefaultPointcutAdvisor(resultPointcut, new TraceAopInterceptor(traceLogManager));
pointcutAdvisor.setOrder(Integer.MAX_VALUE);
return pointcutAdvisor;
}
示例4: getAdvisor
import org.springframework.aop.aspectj.AspectJExpressionPointcut; //导入依赖的package包/类
@Override
public Advisor getAdvisor(Method candidateAdviceMethod, MetadataAwareAspectInstanceFactory aif,
int declarationOrderInAspect, String aspectName) {
validate(aif.getAspectMetadata().getAspectClass());
AspectJExpressionPointcut ajexp =
getPointcut(candidateAdviceMethod, aif.getAspectMetadata().getAspectClass());
if (ajexp == null) {
return null;
}
return new InstantiationModelAwarePointcutAdvisorImpl(
this, ajexp, aif, candidateAdviceMethod, declarationOrderInAspect, aspectName);
}
示例5: getPointcut
import org.springframework.aop.aspectj.AspectJExpressionPointcut; //导入依赖的package包/类
private AspectJExpressionPointcut getPointcut(Method candidateAdviceMethod, Class<?> candidateAspectClass) {
AspectJAnnotation<?> aspectJAnnotation =
AbstractAspectJAdvisorFactory.findAspectJAnnotationOnMethod(candidateAdviceMethod);
if (aspectJAnnotation == null) {
return null;
}
AspectJExpressionPointcut ajexp =
new AspectJExpressionPointcut(candidateAspectClass, new String[0], new Class<?>[0]);
ajexp.setExpression(aspectJAnnotation.getPointcutExpression());
return ajexp;
}
示例6: createPointcutExpression
import org.springframework.aop.aspectj.AspectJExpressionPointcut; //导入依赖的package包/类
/**
* The pointcut and advice annotations both have an "argNames" member which contains a
* comma-separated list of the argument names. We use this (if non-empty) to build the
* formal parameters for the pointcut.
*/
protected AspectJExpressionPointcut createPointcutExpression(
Method annotatedMethod, Class<?> declarationScope, String[] pointcutParameterNames) {
Class<?> [] pointcutParameterTypes = new Class<?>[0];
if (pointcutParameterNames != null) {
pointcutParameterTypes = extractPointcutParameterTypes(pointcutParameterNames,annotatedMethod);
}
AspectJExpressionPointcut ajexp =
new AspectJExpressionPointcut(declarationScope,pointcutParameterNames,pointcutParameterTypes);
ajexp.setLocation(annotatedMethod.toString());
return ajexp;
}
示例7: InstantiationModelAwarePointcutAdvisorImpl
import org.springframework.aop.aspectj.AspectJExpressionPointcut; //导入依赖的package包/类
public InstantiationModelAwarePointcutAdvisorImpl(AspectJAdvisorFactory af, AspectJExpressionPointcut ajexp,
MetadataAwareAspectInstanceFactory aif, Method method, int declarationOrderInAspect, String aspectName) {
this.declaredPointcut = ajexp;
this.method = method;
this.atAspectJAdvisorFactory = af;
this.aspectInstanceFactory = aif;
this.declarationOrder = declarationOrderInAspect;
this.aspectName = aspectName;
if (aif.getAspectMetadata().isLazilyInstantiated()) {
// Static part of the pointcut is a lazy type.
Pointcut preInstantiationPointcut =
Pointcuts.union(aif.getAspectMetadata().getPerClausePointcut(), this.declaredPointcut);
// Make it dynamic: must mutate from pre-instantiation to post-instantiation state.
// If it's not a dynamic pointcut, it may be optimized out
// by the Spring AOP infrastructure after the first evaluation.
this.pointcut = new PerTargetInstantiationModelPointcut(this.declaredPointcut, preInstantiationPointcut, aif);
this.lazy = true;
}
else {
// A singleton aspect.
this.instantiatedAdvice = instantiateAdvice(this.declaredPointcut);
this.pointcut = declaredPointcut;
this.lazy = false;
}
}
示例8: PerTargetInstantiationModelPointcut
import org.springframework.aop.aspectj.AspectJExpressionPointcut; //导入依赖的package包/类
private PerTargetInstantiationModelPointcut(AspectJExpressionPointcut declaredPointcut,
Pointcut preInstantiationPointcut, MetadataAwareAspectInstanceFactory aspectInstanceFactory) {
this.declaredPointcut = declaredPointcut;
this.preInstantiationPointcut = preInstantiationPointcut;
if (aspectInstanceFactory instanceof LazySingletonAspectInstanceFactoryDecorator) {
this.aspectInstanceFactory = (LazySingletonAspectInstanceFactoryDecorator) aspectInstanceFactory;
}
}
示例9: createPointcutDefinition
import org.springframework.aop.aspectj.AspectJExpressionPointcut; //导入依赖的package包/类
/**
* Creates a {@link BeanDefinition} for the {@link AspectJExpressionPointcut} class using
* the supplied pointcut expression.
*/
protected AbstractBeanDefinition createPointcutDefinition(String expression) {
RootBeanDefinition beanDefinition = new RootBeanDefinition(AspectJExpressionPointcut.class);
beanDefinition.setScope(BeanDefinition.SCOPE_PROTOTYPE);
beanDefinition.setSynthetic(true);
beanDefinition.getPropertyValues().add(EXPRESSION, expression);
return beanDefinition;
}
示例10: testSingleton
import org.springframework.aop.aspectj.AspectJExpressionPointcut; //导入依赖的package包/类
@Test
public void testSingleton() throws SecurityException, NoSuchMethodException {
AspectJExpressionPointcut ajexp = new AspectJExpressionPointcut();
ajexp.setExpression(AspectJExpressionPointcutTests.MATCH_ALL_METHODS);
InstantiationModelAwarePointcutAdvisorImpl ajpa = new InstantiationModelAwarePointcutAdvisorImpl(af, ajexp,
new SingletonMetadataAwareAspectInstanceFactory(new AbstractAspectJAdvisorFactoryTests.ExceptionAspect(null),"someBean"),
TestBean.class.getMethod("getAge", (Class[]) null),1,"someBean");
assertSame(Pointcut.TRUE, ajpa.getAspectMetadata().getPerClausePointcut());
assertFalse(ajpa.isPerInstance());
}
示例11: setUp
import org.springframework.aop.aspectj.AspectJExpressionPointcut; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
this.comparator = new AspectJPrecedenceComparator();
this.anyOldMethod = getClass().getMethods()[0];
this.anyOldPointcut = new AspectJExpressionPointcut();
this.anyOldPointcut.setExpression("execution(* *(..))");
}
示例12: manualGroovyBeanWithStaticPointcut
import org.springframework.aop.aspectj.AspectJExpressionPointcut; //导入依赖的package包/类
@Test
public void manualGroovyBeanWithStaticPointcut() throws Exception {
TestService target = (TestService) scriptFactory.getScriptedObject(new ResourceScriptSource(
new ClassPathResource("GroovyServiceImpl.grv", getClass())));
AspectJExpressionPointcut pointcut = new AspectJExpressionPointcut();
pointcut.setExpression(String.format("execution(* %s.TestService+.*(..))", ClassUtils.getPackageName(getClass())));
testAdvice(new DefaultPointcutAdvisor(pointcut, logAdvice), logAdvice, target, "GroovyServiceImpl", true);
}
示例13: manualGroovyBeanWithDynamicPointcut
import org.springframework.aop.aspectj.AspectJExpressionPointcut; //导入依赖的package包/类
@Test
public void manualGroovyBeanWithDynamicPointcut() throws Exception {
TestService target = (TestService) scriptFactory.getScriptedObject(new ResourceScriptSource(
new ClassPathResource("GroovyServiceImpl.grv", getClass())));
AspectJExpressionPointcut pointcut = new AspectJExpressionPointcut();
pointcut.setExpression(String.format("@within(%s.Log)", ClassUtils.getPackageName(getClass())));
testAdvice(new DefaultPointcutAdvisor(pointcut, logAdvice), logAdvice, target, "GroovyServiceImpl", false);
}
示例14: manualGroovyBeanWithDynamicPointcutProxyTargetClass
import org.springframework.aop.aspectj.AspectJExpressionPointcut; //导入依赖的package包/类
@Test
public void manualGroovyBeanWithDynamicPointcutProxyTargetClass() throws Exception {
TestService target = (TestService) scriptFactory.getScriptedObject(new ResourceScriptSource(
new ClassPathResource("GroovyServiceImpl.grv", getClass())));
AspectJExpressionPointcut pointcut = new AspectJExpressionPointcut();
pointcut.setExpression(String.format("@within(%s.Log)", ClassUtils.getPackageName(getClass())));
testAdvice(new DefaultPointcutAdvisor(pointcut, logAdvice), logAdvice, target, "GroovyServiceImpl", true);
}
示例15: createDbShardInterceptor
import org.springframework.aop.aspectj.AspectJExpressionPointcut; //导入依赖的package包/类
public static DefaultPointcutAdvisor createDbShardInterceptor(String springAop) {
DefaultPointcutAdvisor re = new DefaultPointcutAdvisor();
AspectJExpressionPointcut aspectJExpressionPointcut = new AspectJExpressionPointcut();
aspectJExpressionPointcut.setExpression(springAop);
re.setPointcut(aspectJExpressionPointcut);
re.setAdvice(new MethodInterceptor() {
public Object invoke(MethodInvocation methodInvocation) throws Throwable {
Object clz = methodInvocation.getThis();
DbRouter annotation = clz.getClass().getAnnotation(DbRouter.class);
if (annotation != null) {
DynamicDataSource.setDb(annotation.value());
Transfer.setForceUseTable(annotation.useTable());
} else {
DbRouter dbRouter = methodInvocation.getMethod().getAnnotation(DbRouter.class);
if (dbRouter != null) {
DynamicDataSource.setDb(dbRouter.value());
Transfer.setForceUseTable(dbRouter.useTable());
}
}
System.out.println("DB----> " + DynamicDataSource.getDb());
try {
return methodInvocation.proceed();
} finally {
DynamicDataSource.clearDb();
Transfer.clear();
}
}
});
return re;
}