本文整理汇总了Java中org.springframework.aop.aspectj.AspectJExpressionPointcut.setExpression方法的典型用法代码示例。如果您正苦于以下问题:Java AspectJExpressionPointcut.setExpression方法的具体用法?Java AspectJExpressionPointcut.setExpression怎么用?Java AspectJExpressionPointcut.setExpression使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.aop.aspectj.AspectJExpressionPointcut
的用法示例。
在下文中一共展示了AspectJExpressionPointcut.setExpression方法的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: 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;
}
示例3: 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));
}
示例4: 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;
}
示例5: 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());
}
示例6: 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);
}
示例7: 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);
}
示例8: 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);
}
示例9: 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;
}
示例10: 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;
}
示例11: traceAdvisor
import org.springframework.aop.aspectj.AspectJExpressionPointcut; //导入方法依赖的package包/类
@Bean
public Advisor traceAdvisor() {
AspectJExpressionPointcut pointcut = new AspectJExpressionPointcut();
pointcut.setExpression("execution(public * org.springframework.data.repository.Repository+.*(..))");
return new DefaultPointcutAdvisor(pointcut, interceptor());
}
示例12: 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;
}
示例13: testManualGroovyBeanWithStaticPointcut
import org.springframework.aop.aspectj.AspectJExpressionPointcut; //导入方法依赖的package包/类
@Test
public void testManualGroovyBeanWithStaticPointcut() throws Exception {
LogUserAdvice logAdvice = new LogUserAdvice();
GroovyScriptFactory scriptFactory = new GroovyScriptFactory("GroovyServiceImpl.grv");
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);
}
示例14: testManualGroovyBeanWithDynamicPointcut
import org.springframework.aop.aspectj.AspectJExpressionPointcut; //导入方法依赖的package包/类
@Test
public void testManualGroovyBeanWithDynamicPointcut() throws Exception {
LogUserAdvice logAdvice = new LogUserAdvice();
GroovyScriptFactory scriptFactory = new GroovyScriptFactory("GroovyServiceImpl.grv");
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);
}
示例15: testManualGroovyBeanWithDynamicPointcutProxyTargetClass
import org.springframework.aop.aspectj.AspectJExpressionPointcut; //导入方法依赖的package包/类
@Test
public void testManualGroovyBeanWithDynamicPointcutProxyTargetClass() throws Exception {
LogUserAdvice logAdvice = new LogUserAdvice();
GroovyScriptFactory scriptFactory = new GroovyScriptFactory("GroovyServiceImpl.grv");
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);
}