本文整理汇总了Java中org.springframework.aop.support.DefaultPointcutAdvisor类的典型用法代码示例。如果您正苦于以下问题:Java DefaultPointcutAdvisor类的具体用法?Java DefaultPointcutAdvisor怎么用?Java DefaultPointcutAdvisor使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DefaultPointcutAdvisor类属于org.springframework.aop.support包,在下文中一共展示了DefaultPointcutAdvisor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: defaultPointcutAdvisor
import org.springframework.aop.support.DefaultPointcutAdvisor; //导入依赖的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: SubsystemProxyFactory
import org.springframework.aop.support.DefaultPointcutAdvisor; //导入依赖的package包/类
/**
* Instantiates a new managed subsystem proxy factory.
*/
public SubsystemProxyFactory()
{
addAdvisor(new DefaultPointcutAdvisor(new MethodInterceptor()
{
public Object invoke(MethodInvocation mi) throws Throwable
{
Method method = mi.getMethod();
try
{
return method.invoke(locateBean(mi), mi.getArguments());
}
catch (InvocationTargetException e)
{
// Unwrap invocation target exceptions
throw e.getTargetException();
}
}
}));
}
示例3: wrap
import org.springframework.aop.support.DefaultPointcutAdvisor; //导入依赖的package包/类
@Override
public Advisor wrap(Object adviceObject) throws UnknownAdviceTypeException {
if (adviceObject instanceof Advisor) {
return (Advisor) adviceObject;
}
if (!(adviceObject instanceof Advice)) {
throw new UnknownAdviceTypeException(adviceObject);
}
Advice advice = (Advice) adviceObject;
if (advice instanceof MethodInterceptor) {
// So well-known it doesn't even need an adapter.
return new DefaultPointcutAdvisor(advice);
}
for (AdvisorAdapter adapter : this.adapters) {
// Check that it is supported.
if (adapter.supportsAdvice(advice)) {
return new DefaultPointcutAdvisor(advice);
}
}
throw new UnknownAdviceTypeException(advice);
}
示例4: addAdvice
import org.springframework.aop.support.DefaultPointcutAdvisor; //导入依赖的package包/类
/**
* Cannot add introductions this way unless the advice implements IntroductionInfo.
*/
@Override
public void addAdvice(int pos, Advice advice) throws AopConfigException {
Assert.notNull(advice, "Advice must not be null");
if (advice instanceof IntroductionInfo) {
// We don't need an IntroductionAdvisor for this kind of introduction:
// It's fully self-describing.
addAdvisor(pos, new DefaultIntroductionAdvisor(advice, (IntroductionInfo) advice));
}
else if (advice instanceof DynamicIntroductionAdvice) {
// We need an IntroductionAdvisor for this kind of introduction.
throw new AopConfigException("DynamicIntroductionAdvice may only be added as part of IntroductionAdvisor");
}
else {
addAdvisor(pos, new DefaultPointcutAdvisor(advice));
}
}
示例5: testManualProxyJavaWithStaticPointcutAndTwoClassLoaders
import org.springframework.aop.support.DefaultPointcutAdvisor; //导入依赖的package包/类
@Test
public void testManualProxyJavaWithStaticPointcutAndTwoClassLoaders() throws Exception {
LogUserAdvice logAdvice = new LogUserAdvice();
AspectJExpressionPointcut pointcut = new AspectJExpressionPointcut();
pointcut.setExpression(String.format("execution(* %s.TestService.*(..))", getClass().getName()));
// Test with default class loader first...
testAdvice(new DefaultPointcutAdvisor(pointcut, logAdvice), logAdvice, new TestServiceImpl(), "TestServiceImpl");
// Then try again with a different class loader on the target...
SimpleThrowawayClassLoader loader = new SimpleThrowawayClassLoader(new TestServiceImpl().getClass().getClassLoader());
// Make sure the interface is loaded from the parent class loader
loader.excludeClass(TestService.class.getName());
loader.excludeClass(TestException.class.getName());
TestService other = (TestService) loader.loadClass(TestServiceImpl.class.getName()).newInstance();
testAdvice(new DefaultPointcutAdvisor(pointcut, logAdvice), logAdvice, other, "TestServiceImpl");
}
示例6: testRemoveAdvisorByReference
import org.springframework.aop.support.DefaultPointcutAdvisor; //导入依赖的package包/类
@Test
public void testRemoveAdvisorByReference() {
TestBean target = new TestBean();
ProxyFactory pf = new ProxyFactory(target);
NopInterceptor nop = new NopInterceptor();
CountingBeforeAdvice cba = new CountingBeforeAdvice();
Advisor advisor = new DefaultPointcutAdvisor(cba);
pf.addAdvice(nop);
pf.addAdvisor(advisor);
ITestBean proxied = (ITestBean) pf.getProxy();
proxied.setAge(5);
assertEquals(1, cba.getCalls());
assertEquals(1, nop.getCount());
assertTrue(pf.removeAdvisor(advisor));
assertEquals(5, proxied.getAge());
assertEquals(1, cba.getCalls());
assertEquals(2, nop.getCount());
assertFalse(pf.removeAdvisor(new DefaultPointcutAdvisor(null)));
}
示例7: testValuesStick
import org.springframework.aop.support.DefaultPointcutAdvisor; //导入依赖的package包/类
/**
* Simple test that if we set values we can get them out again.
*/
@Test
public void testValuesStick() {
int age1 = 33;
int age2 = 37;
String name = "tony";
TestBean target1 = new TestBean();
target1.setAge(age1);
ProxyFactory pf1 = new ProxyFactory(target1);
pf1.addAdvisor(new DefaultPointcutAdvisor(new NopInterceptor()));
pf1.addAdvisor(new DefaultPointcutAdvisor(new TimestampIntroductionInterceptor()));
ITestBean tb = (ITestBean) pf1.getProxy();
assertEquals(age1, tb.getAge());
tb.setAge(age2);
assertEquals(age2, tb.getAge());
assertNull(tb.getName());
tb.setName(name);
assertEquals(name, tb.getName());
}
示例8: testCannotAddAdvisorWhenFrozenUsingCast
import org.springframework.aop.support.DefaultPointcutAdvisor; //导入依赖的package包/类
/**
* Check that casting to Advised can't get around advice freeze.
*/
@Test
public void testCannotAddAdvisorWhenFrozenUsingCast() throws Throwable {
TestBean target = new TestBean();
target.setAge(21);
ProxyFactory pc = new ProxyFactory(target);
assertFalse(pc.isFrozen());
pc.addAdvice(new NopInterceptor());
ITestBean proxied = (ITestBean) createProxy(pc);
pc.setFrozen(true);
Advised advised = (Advised) proxied;
assertTrue(pc.isFrozen());
try {
advised.addAdvisor(new DefaultPointcutAdvisor(new NopInterceptor()));
fail("Shouldn't be able to add Advisor when frozen");
}
catch (AopConfigException ex) {
assertTrue(ex.getMessage().indexOf("frozen") > -1);
}
// Check it still works: proxy factory state shouldn't have been corrupted
assertEquals(target.getAge(), proxied.getAge());
assertEquals(1, advised.getAdvisors().length);
}
示例9: testProxyConfigString
import org.springframework.aop.support.DefaultPointcutAdvisor; //导入依赖的package包/类
/**
* Check that the string is informative.
*/
@Test
public void testProxyConfigString() {
TestBean target = new TestBean();
ProxyFactory pc = new ProxyFactory(target);
pc.setInterfaces(new Class<?>[] {ITestBean.class});
pc.addAdvice(new NopInterceptor());
MethodBeforeAdvice mba = new CountingBeforeAdvice();
Advisor advisor = new DefaultPointcutAdvisor(new NameMatchMethodPointcut(), mba);
pc.addAdvisor(advisor);
ITestBean proxied = (ITestBean) createProxy(pc);
String proxyConfigString = ((Advised) proxied).toProxyConfigString();
assertTrue(proxyConfigString.indexOf(advisor.toString()) != -1);
assertTrue(proxyConfigString.indexOf("1 interface") != -1);
}
示例10: testCanPreventCastToAdvisedUsingOpaque
import org.springframework.aop.support.DefaultPointcutAdvisor; //导入依赖的package包/类
@Test
public void testCanPreventCastToAdvisedUsingOpaque() {
TestBean target = new TestBean();
ProxyFactory pc = new ProxyFactory(target);
pc.setInterfaces(new Class<?>[] {ITestBean.class});
pc.addAdvice(new NopInterceptor());
CountingBeforeAdvice mba = new CountingBeforeAdvice();
Advisor advisor = new DefaultPointcutAdvisor(new NameMatchMethodPointcut().addMethodName("setAge"), mba);
pc.addAdvisor(advisor);
assertFalse("Opaque defaults to false", pc.isOpaque());
pc.setOpaque(true);
assertTrue("Opaque now true for this config", pc.isOpaque());
ITestBean proxied = (ITestBean) createProxy(pc);
proxied.setAge(10);
assertEquals(10, proxied.getAge());
assertEquals(1, mba.getCalls());
assertFalse("Cannot be cast to Advised", proxied instanceof Advised);
}
示例11: initServlet
import org.springframework.aop.support.DefaultPointcutAdvisor; //导入依赖的package包/类
@SuppressWarnings("serial")
private void initServlet(final Class<?> controllerclass) throws ServletException {
servlet = new DispatcherServlet() {
@Override
protected WebApplicationContext createWebApplicationContext(WebApplicationContext parent)
throws BeansException {
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);
wac.getBeanFactory().registerSingleton("advisor", new DefaultPointcutAdvisor(new SimpleTraceInterceptor(true)));
wac.refresh();
return wac;
}
};
servlet.init(new MockServletConfig());
}
示例12: initServlet
import org.springframework.aop.support.DefaultPointcutAdvisor; //导入依赖的package包/类
@SuppressWarnings("serial")
private void initServlet(final Class<?> controllerclass) throws ServletException {
servlet = new DispatcherServlet() {
@Override
protected WebApplicationContext createWebApplicationContext(WebApplicationContext parent)
throws BeansException {
GenericWebApplicationContext wac = new GenericWebApplicationContext();
wac.registerBeanDefinition("controller", new RootBeanDefinition(controllerclass));
DefaultAdvisorAutoProxyCreator autoProxyCreator = new DefaultAdvisorAutoProxyCreator();
autoProxyCreator.setBeanFactory(wac.getBeanFactory());
wac.getBeanFactory().addBeanPostProcessor(autoProxyCreator);
wac.getBeanFactory().registerSingleton("advisor", new DefaultPointcutAdvisor(new SimpleTraceInterceptor(true)));
wac.refresh();
return wac;
}
};
servlet.init(new MockServletConfig());
}
示例13: proxiedStandardHandleMethod
import org.springframework.aop.support.DefaultPointcutAdvisor; //导入依赖的package包/类
@Test
@SuppressWarnings("serial")
public void proxiedStandardHandleMethod() throws Exception {
DispatcherServlet servlet = new DispatcherServlet() {
@Override
protected WebApplicationContext createWebApplicationContext(WebApplicationContext parent) {
GenericWebApplicationContext wac = new GenericWebApplicationContext();
wac.registerBeanDefinition("controller", new RootBeanDefinition(MyController.class));
DefaultAdvisorAutoProxyCreator autoProxyCreator = new DefaultAdvisorAutoProxyCreator();
autoProxyCreator.setBeanFactory(wac.getBeanFactory());
wac.getBeanFactory().addBeanPostProcessor(autoProxyCreator);
wac.getBeanFactory().registerSingleton("advisor", new DefaultPointcutAdvisor(new SimpleTraceInterceptor()));
wac.refresh();
return wac;
}
};
servlet.init(new MockServletConfig());
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/myPath.do");
MockHttpServletResponse response = new MockHttpServletResponse();
servlet.service(request, response);
assertEquals("test", response.getContentAsString());
}
示例14: proxiedFormController
import org.springframework.aop.support.DefaultPointcutAdvisor; //导入依赖的package包/类
@Test
public void proxiedFormController() throws Exception {
initServlet(new ApplicationContextInitializer<GenericWebApplicationContext>() {
@Override
public void initialize(GenericWebApplicationContext wac) {
wac.registerBeanDefinition("viewResolver", new RootBeanDefinition(TestViewResolver.class));
DefaultAdvisorAutoProxyCreator autoProxyCreator = new DefaultAdvisorAutoProxyCreator();
autoProxyCreator.setBeanFactory(wac.getBeanFactory());
wac.getBeanFactory().addBeanPostProcessor(autoProxyCreator);
wac.getBeanFactory()
.registerSingleton("advisor", new DefaultPointcutAdvisor(new SimpleTraceInterceptor()));
}
}, MyFormController.class);
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/myPath.do");
request.addParameter("name", "name1");
request.addParameter("age", "value2");
MockHttpServletResponse response = new MockHttpServletResponse();
getServlet().service(request, response);
assertEquals("myView-name1-typeMismatch-tb1-myValue", response.getContentAsString());
}
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:22,代码来源:ServletAnnotationControllerHandlerMethodTests.java
示例15: requestMappingInterfaceWithProxy
import org.springframework.aop.support.DefaultPointcutAdvisor; //导入依赖的package包/类
@Test
public void requestMappingInterfaceWithProxy() throws Exception {
initServlet(new ApplicationContextInitializer<GenericWebApplicationContext>() {
@Override
public void initialize(GenericWebApplicationContext wac) {
DefaultAdvisorAutoProxyCreator autoProxyCreator = new DefaultAdvisorAutoProxyCreator();
autoProxyCreator.setBeanFactory(wac.getBeanFactory());
wac.getBeanFactory().addBeanPostProcessor(autoProxyCreator);
wac.getBeanFactory().registerSingleton("advisor", new DefaultPointcutAdvisor(new SimpleTraceInterceptor()));
}
}, IMyControllerImpl.class);
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/handle");
MockHttpServletResponse response = new MockHttpServletResponse();
getServlet().service(request, response);
assertEquals("handle null", response.getContentAsString());
request = new MockHttpServletRequest("GET", "/handle");
request.addParameter("p", "value");
response = new MockHttpServletResponse();
getServlet().service(request, response);
assertEquals("handle value", response.getContentAsString());
}
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:24,代码来源:ServletAnnotationControllerHandlerMethodTests.java