当前位置: 首页>>代码示例>>Java>>正文


Java Advised.getAdvisors方法代码示例

本文整理汇总了Java中org.springframework.aop.framework.Advised.getAdvisors方法的典型用法代码示例。如果您正苦于以下问题:Java Advised.getAdvisors方法的具体用法?Java Advised.getAdvisors怎么用?Java Advised.getAdvisors使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.springframework.aop.framework.Advised的用法示例。


在下文中一共展示了Advised.getAdvisors方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: applyTo

import org.springframework.aop.framework.Advised; //导入方法依赖的package包/类
@Autowired
public static void applyTo(Object source) {
	Assert.state(AopUtils.isAopProxy(source), "Source must be an AOP proxy");
	try {
		Advised advised = (Advised) source;
		for (Advisor advisor : advised.getAdvisors()) {
			if (advisor instanceof MockitoAopProxyTargetInterceptor) {
				return;
			}
		}
		Object target = AopTestUtils.getUltimateTargetObject(source);
		Advice advice = new MockitoAopProxyTargetInterceptor(source, target);
		advised.addAdvice(0, advice);
	}
	catch (Exception ex) {
		throw new IllegalStateException("Unable to apply Mockito AOP support", ex);
	}
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:19,代码来源:MockitoAopProxyTargetInterceptor.java

示例2: postProcessAfterInitialization

import org.springframework.aop.framework.Advised; //导入方法依赖的package包/类
@Override
public Object postProcessAfterInitialization(Object bean, String beanName)
		throws BeansException {
	if (bean instanceof Advised) {
		Advised advised = (Advised) bean;

		for (Advisor advisor : advised.getAdvisors()) {
			if (advisor instanceof AspectJPointcutAdvisor) {
				String foundName = ((AbstractAspectJAdvice) ((AspectJPointcutAdvisor) advisor)
						.getAdvice()).getAspectName();
				if (aspect.getName().equals(foundName)) {
					LOG.info(String.format("Found bean '%s' advised by %s; injecting", beanName, aspect));
					try {
						aspect.addAdvised(advised.getTargetSource().getTarget(), beanName);
					} catch (Exception e) {
						throw new RuntimeException(e);
					}
				}
			}
		}
	}
	return bean;
}
 
开发者ID:performancecopilot,项目名称:parfait,代码行数:24,代码来源:AdviceNotifier.java

示例3: extractPojo

import org.springframework.aop.framework.Advised; //导入方法依赖的package包/类
private Object extractPojo(MyService svc)
{
	Advised advisedBean = (Advised) svc;
	Advisor[] advisors = advisedBean.getAdvisors();
	for(Advisor advisor : advisors)
	{
		Advice advice = advisor.getAdvice();
		if(advice instanceof AbstractAspectJAdvice)
		{
			AbstractAspectJAdvice aaja = (AbstractAspectJAdvice) advice;
			Object target = aaja.getAspectInstanceFactory().getAspectInstance();
			return target;
		}
	}
	return null;
}
 
开发者ID:kenwdelong,项目名称:stability-utils,代码行数:17,代码来源:JmxExportingAspectCircuitBreakerBeanPostprocessorTest.java

示例4: verifyAddingRedirectAdviceToExistingProxy

import org.springframework.aop.framework.Advised; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Test
public void verifyAddingRedirectAdviceToExistingProxy() {

    AmazonS3 amazonS3 = mock(AmazonS3.class);

    ProxyFactory factory = new ProxyFactory(amazonS3);
    factory.addAdvice(new TestAdvice());
    AmazonS3 proxy1 = (AmazonS3) factory.getProxy();

    assertThat(((Advised) proxy1).getAdvisors().length, is(1));

    AmazonS3 proxy2 = AmazonS3ProxyFactory.createProxy(proxy1);
    Advised advised = (Advised) proxy2;

    assertThat(advised.getAdvisors().length, is(2));

    List<Class<? extends MethodInterceptor>> advisorClasses = new ArrayList<>();
    for (Advisor advisor : advised.getAdvisors()) {
        advisorClasses.add(((MethodInterceptor) advisor.getAdvice()).getClass());
    }
    assertThat(advisorClasses, hasItems(TestAdvice.class, AmazonS3ProxyFactory.SimpleStorageRedirectInterceptor.class));

}
 
开发者ID:spring-cloud,项目名称:spring-cloud-aws,代码行数:25,代码来源:AmazonS3ProxyFactoryTest.java

示例5: testPerTargetAspect

import org.springframework.aop.framework.Advised; //导入方法依赖的package包/类
@Test
public void testPerTargetAspect() throws SecurityException, NoSuchMethodException {
	TestBean target = new TestBean();
	int realAge = 65;
	target.setAge(realAge);
	TestBean itb = (TestBean) createProxy(target,
			getFixture().getAdvisors(new SingletonMetadataAwareAspectInstanceFactory(new PerTargetAspect(), "someBean")),
			TestBean.class);
	assertEquals("Around advice must NOT apply", realAge, itb.getAge());

	Advised advised = (Advised) itb;
	SyntheticInstantiationAdvisor sia = (SyntheticInstantiationAdvisor) advised.getAdvisors()[1];
	assertTrue(sia.getPointcut().getMethodMatcher().matches(TestBean.class.getMethod("getSpouse"), null));
	InstantiationModelAwarePointcutAdvisorImpl imapa = (InstantiationModelAwarePointcutAdvisorImpl) advised.getAdvisors()[3];
	LazySingletonAspectInstanceFactoryDecorator maaif =
			(LazySingletonAspectInstanceFactoryDecorator) imapa.getAspectInstanceFactory();
	assertFalse(maaif.isMaterialized());

	// Check that the perclause pointcut is valid
	assertTrue(maaif.getAspectMetadata().getPerClausePointcut().getMethodMatcher().matches(TestBean.class.getMethod("getSpouse"), null));
	assertNotSame(imapa.getDeclaredPointcut(), imapa.getPointcut());

	// Hit the method in the per clause to instantiate the aspect
	itb.getSpouse();

	assertTrue(maaif.isMaterialized());

	assertEquals("Around advice must apply", 0, itb.getAge());
	assertEquals("Around advice must apply", 1, itb.getAge());
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:31,代码来源:AbstractAspectJAdvisorFactoryTests.java

示例6: testPerThisAspect

import org.springframework.aop.framework.Advised; //导入方法依赖的package包/类
@Test
public void testPerThisAspect() throws SecurityException, NoSuchMethodException {
	TestBean target = new TestBean();
	int realAge = 65;
	target.setAge(realAge);
	TestBean itb = (TestBean) createProxy(target,
			getFixture().getAdvisors(new SingletonMetadataAwareAspectInstanceFactory(new PerThisAspect(), "someBean")),
			TestBean.class);
	assertEquals("Around advice must NOT apply", realAge, itb.getAge());

	Advised advised = (Advised) itb;
	// Will be ExposeInvocationInterceptor, synthetic instantiation advisor, 2 method advisors
	assertEquals(4, advised.getAdvisors().length);
	SyntheticInstantiationAdvisor sia = (SyntheticInstantiationAdvisor) advised.getAdvisors()[1];
	assertTrue(sia.getPointcut().getMethodMatcher().matches(TestBean.class.getMethod("getSpouse"), null));
	InstantiationModelAwarePointcutAdvisorImpl imapa = (InstantiationModelAwarePointcutAdvisorImpl) advised.getAdvisors()[2];
	LazySingletonAspectInstanceFactoryDecorator maaif =
			(LazySingletonAspectInstanceFactoryDecorator) imapa.getAspectInstanceFactory();
	assertFalse(maaif.isMaterialized());

	// Check that the perclause pointcut is valid
	assertTrue(maaif.getAspectMetadata().getPerClausePointcut().getMethodMatcher().matches(TestBean.class.getMethod("getSpouse"), null));
	assertNotSame(imapa.getDeclaredPointcut(), imapa.getPointcut());

	// Hit the method in the per clause to instantiate the aspect
	itb.getSpouse();

	assertTrue(maaif.isMaterialized());

	assertTrue(imapa.getDeclaredPointcut().getMethodMatcher().matches(TestBean.class.getMethod("getAge"), null));

	assertEquals("Around advice must apply", 0, itb.getAge());
	assertEquals("Around advice must apply", 1, itb.getAge());
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:35,代码来源:AbstractAspectJAdvisorFactoryTests.java

示例7: testIsProxy

import org.springframework.aop.framework.Advised; //导入方法依赖的package包/类
@Test
public void testIsProxy() throws Exception {
	ITestBean bean = getTestBean();

	assertTrue("Bean is not a proxy", AopUtils.isAopProxy(bean));

	// check the advice details
	Advised advised = (Advised) bean;
	Advisor[] advisors = advised.getAdvisors();

	assertTrue("Advisors should not be empty", advisors.length > 0);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:13,代码来源:AopNamespaceHandlerTests.java

示例8: checkWillTranslateExceptions

import org.springframework.aop.framework.Advised; //导入方法依赖的package包/类
protected void checkWillTranslateExceptions(Object o) {
	assertTrue(o instanceof Advised);
	Advised a = (Advised) o;
	for (Advisor advisor : a.getAdvisors()) {
		if (advisor instanceof PersistenceExceptionTranslationAdvisor) {
			return;
		}
	}
	fail("No translation");
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:11,代码来源:PersistenceExceptionTranslationPostProcessorTests.java

示例9: postProcessAfterInitialization

import org.springframework.aop.framework.Advised; //导入方法依赖的package包/类
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException
{
	boolean advised = bean instanceof Advised;
	if(advised)
	{
		Advised advisedBean = (Advised) bean;
		Advisor[] advisors = advisedBean.getAdvisors();
		for(Advisor advisor : advisors)
		{
			Advice advice = advisor.getAdvice();
			if(advice instanceof AbstractAspectJAdvice)
			{
				AbstractAspectJAdvice aaja = (AbstractAspectJAdvice) advice;
				Class<?> aspectPojoClass = aaja.getAspectJAdviceMethod().getDeclaringClass();
				String serviceType = annotationToServiceNames.get(aspectPojoClass);
				if(serviceType != null)
				{
					ObjectName oname;
					String onameString = getDomain(bean) + "." + serviceType + ":bean=" + beanName;
					try
					{
						/* as long as the aspect is marked prototype, each advised bean
						 * gets a new instance, as seen by the return value of this next 
						 * method call.  I've also checked that successive calls to the
						 * getAspectInstance() method return the same object.
						 */
						Object target = aaja.getAspectInstanceFactory().getAspectInstance();
						oname = new ObjectName(onameString);
						registerMBean(oname, target, beanName);
					}
					catch(Exception e)
					{
						logger.error("Cannot register mbean with oname [" + onameString +"]", e);
					}
				}
			}
		}
	}
	return bean;
}
 
开发者ID:kenwdelong,项目名称:stability-utils,代码行数:41,代码来源:JmxExportingAspectPostProcessor.java

示例10: createProxy

import org.springframework.aop.framework.Advised; //导入方法依赖的package包/类
/**
 * Factory-method to create a proxy using the {@link SimpleStorageRedirectInterceptor} that supports redirects for
 * buckets which are in a different region. This proxy uses the amazonS3 parameter as a "prototype" and re-uses
 * the credentials from the passed in {@link AmazonS3} instance.
 * Proxy implementations uses the {@link AmazonS3ClientFactory} to create region specific clients, which are cached
 * by the implementation on a region basis to avoid unnecessary object creation.
 *
 * @param amazonS3
 *         Fully configured AmazonS3 client, the client can be an immutable instance
 *         (created by the {@link com.amazonaws.services.s3.AmazonS3ClientBuilder}) as this proxy will not
 *         change the underlying implementation.
 * @return AOP-Proxy that intercepts all method calls using the {@link SimpleStorageRedirectInterceptor}
 */
static AmazonS3 createProxy(AmazonS3 amazonS3) {
    Assert.notNull(amazonS3, "AmazonS3 client must not be null");

    if (AopUtils.isAopProxy(amazonS3)) {

        Advised advised = (Advised) amazonS3;
        for (Advisor advisor : advised.getAdvisors()) {
            if (ClassUtils.isAssignableValue(SimpleStorageRedirectInterceptor.class, advisor.getAdvice())) {
                return amazonS3;
            }
        }

        try {
            advised.addAdvice(new SimpleStorageRedirectInterceptor((AmazonS3) advised.getTargetSource().getTarget()));
        } catch (Exception e) {
            throw new RuntimeException("Error adding advice for class amazonS3 instance", e);
        }

        return amazonS3;
    }

    ProxyFactory factory = new ProxyFactory(amazonS3);
    factory.setInterfaces(AmazonS3.class);
    factory.addAdvice(new SimpleStorageRedirectInterceptor(amazonS3));

    return (AmazonS3) factory.getProxy();
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-aws,代码行数:41,代码来源:AmazonS3ProxyFactory.java

示例11: testPerTypeWithinAspect

import org.springframework.aop.framework.Advised; //导入方法依赖的package包/类
@Test
public void testPerTypeWithinAspect() throws SecurityException, NoSuchMethodException {
	TestBean target = new TestBean();
	int realAge = 65;
	target.setAge(realAge);
	PerTypeWithinAspectInstanceFactory aif = new PerTypeWithinAspectInstanceFactory();
	TestBean itb = (TestBean) createProxy(target,
			getFixture().getAdvisors(aif),
			TestBean.class);
	assertEquals("No method calls", 0, aif.getInstantiationCount());
	assertEquals("Around advice must now apply", 0, itb.getAge());

	Advised advised = (Advised) itb;
	// Will be ExposeInvocationInterceptor, synthetic instantiation advisor, 2 method advisors
	assertEquals(4, advised.getAdvisors().length);
	SyntheticInstantiationAdvisor sia = (SyntheticInstantiationAdvisor) advised.getAdvisors()[1];
	assertTrue(sia.getPointcut().getMethodMatcher().matches(TestBean.class.getMethod("getSpouse"), null));
	InstantiationModelAwarePointcutAdvisorImpl imapa = (InstantiationModelAwarePointcutAdvisorImpl) advised.getAdvisors()[2];
	LazySingletonAspectInstanceFactoryDecorator maaif =
			(LazySingletonAspectInstanceFactoryDecorator) imapa.getAspectInstanceFactory();
	assertTrue(maaif.isMaterialized());

	// Check that the perclause pointcut is valid
	assertTrue(maaif.getAspectMetadata().getPerClausePointcut().getMethodMatcher().matches(TestBean.class.getMethod("getSpouse"), null));
	assertNotSame(imapa.getDeclaredPointcut(), imapa.getPointcut());

	// Hit the method in the per clause to instantiate the aspect
	itb.getSpouse();

	assertTrue(maaif.isMaterialized());

	assertTrue(imapa.getDeclaredPointcut().getMethodMatcher().matches(TestBean.class.getMethod("getAge"), null));

	assertEquals("Around advice must still apply", 1, itb.getAge());
	assertEquals("Around advice must still apply", 2, itb.getAge());

	TestBean itb2 = (TestBean) createProxy(target,
			getFixture().getAdvisors(aif),
			TestBean.class);
	assertEquals(1, aif.getInstantiationCount());
	assertEquals("Around advice be independent for second instance", 0, itb2.getAge());
	assertEquals(2, aif.getInstantiationCount());
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:44,代码来源:AbstractAspectJAdvisorFactoryTests.java

示例12: getAdviceImpl

import org.springframework.aop.framework.Advised; //导入方法依赖的package包/类
private SimpleBeforeAdviceImpl getAdviceImpl(ITestBean tb) {
	Advised advised = (Advised) tb;
	Advisor advisor = advised.getAdvisors()[0];
	return (SimpleBeforeAdviceImpl) advisor.getAdvice();
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:6,代码来源:AdvisorAdapterRegistrationTests.java


注:本文中的org.springframework.aop.framework.Advised.getAdvisors方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。