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


Java ProxyFactory.setProxyTargetClass方法代码示例

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


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

示例1: getDisposalLockProxy

import org.springframework.aop.framework.ProxyFactory; //导入方法依赖的package包/类
/**
 * Apply a lock (preferably a read lock allowing multiple concurrent access) to the bean. Callers should replace the
 * bean input with the output.
 *
 * @param bean the bean to lock
 * @param lock the lock to apply
 * @return a proxy that locks while its methods are executed
 */
private Object getDisposalLockProxy(Object bean, final Lock lock) {
    ProxyFactory factory = new ProxyFactory(bean);
    factory.setProxyTargetClass(proxyTargetClass);
    factory.addAdvice(new MethodInterceptor() {
        public Object invoke(MethodInvocation invocation) throws Throwable {
            lock.lock();
            try {
                return invocation.proceed();
            } finally {
                lock.unlock();
            }
        }
    });
    return factory.getProxy();
}
 
开发者ID:zouzhirong,项目名称:configx,代码行数:24,代码来源:StandardBeanLifecycleDecorator.java

示例2: configureFactoryForClass

import org.springframework.aop.framework.ProxyFactory; //导入方法依赖的package包/类
/**
 * Based on the given class, properly instructs the ProxyFactory proxies. For additional sanity checks on the passed
 * classes, check the methods below.
 * 
 * @see #containsUnrelatedClasses(Class[])
 * @see #removeParents(Class[])
 * 
 * @param factory
 * @param classes
 */
public static void configureFactoryForClass(ProxyFactory factory, Class<?>[] classes) {
	if (ObjectUtils.isEmpty(classes))
		return;

	for (int i = 0; i < classes.length; i++) {
		Class<?> clazz = classes[i];

		if (clazz.isInterface()) {
			factory.addInterface(clazz);
		} else {
			factory.setTargetClass(clazz);
			factory.setProxyTargetClass(true);
		}
	}
}
 
开发者ID:eclipse,项目名称:gemini.blueprint,代码行数:26,代码来源:ClassUtils.java

示例3: createRefreshableProxy

import org.springframework.aop.framework.ProxyFactory; //导入方法依赖的package包/类
/**
 * Create a refreshable proxy for the given AOP TargetSource.
 * @param ts the refreshable TargetSource
 * @param interfaces the proxy interfaces (may be {@code null} to
 * indicate proxying of all interfaces implemented by the target class)
 * @return the generated proxy
 * @see RefreshableScriptTargetSource
 */
protected Object createRefreshableProxy(TargetSource ts, Class<?>[] interfaces, boolean proxyTargetClass) {
	ProxyFactory proxyFactory = new ProxyFactory();
	proxyFactory.setTargetSource(ts);
	ClassLoader classLoader = this.beanClassLoader;

	if (interfaces == null) {
		interfaces = ClassUtils.getAllInterfacesForClass(ts.getTargetClass(), this.beanClassLoader);
	}
	proxyFactory.setInterfaces(interfaces);
	if (proxyTargetClass) {
		classLoader = null;  // force use of Class.getClassLoader()
		proxyFactory.setProxyTargetClass(proxyTargetClass);
	}

	DelegatingIntroductionInterceptor introduction = new DelegatingIntroductionInterceptor(ts);
	introduction.suppressInterface(TargetSource.class);
	proxyFactory.addAdvice(introduction);

	return proxyFactory.getProxy(classLoader);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:29,代码来源:ScriptFactoryPostProcessor.java

示例4: createRefreshableProxy

import org.springframework.aop.framework.ProxyFactory; //导入方法依赖的package包/类
/**
    * Create a refreshable proxy for the given AOP TargetSource.
    * 
    * @param ts
    *            the refreshable TargetSource
    * @param interfaces
    *            the proxy interfaces (may be {@code null} to indicate proxying
    *            of all interfaces implemented by the target class)
    * @return the generated proxy
    * @see RefreshableScriptTargetSource
    */
   protected Object createRefreshableProxy(TargetSource ts, Class<?>[] interfaces, boolean proxyTargetClass) {
ProxyFactory proxyFactory = new ProxyFactory();
proxyFactory.setTargetSource(ts);
ClassLoader classLoader = this.beanClassLoader;

if (interfaces == null) {
    interfaces = ClassUtils.getAllInterfacesForClass(ts.getTargetClass(), this.beanClassLoader);
}
proxyFactory.setInterfaces(interfaces);
if (proxyTargetClass) {
    classLoader = null; // force use of Class.getClassLoader()
    proxyFactory.setProxyTargetClass(true);
}

DelegatingIntroductionInterceptor introduction = new DelegatingIntroductionInterceptor(ts);
introduction.suppressInterface(TargetSource.class);
proxyFactory.addAdvice(introduction);

return proxyFactory.getProxy(classLoader);
   }
 
开发者ID:ilivoo,项目名称:game,代码行数:32,代码来源:MyScriptFactoryPostProcessor.java

示例5: createProxy

import org.springframework.aop.framework.ProxyFactory; //导入方法依赖的package包/类
protected Object createProxy(Object target, List<Advisor> advisors, Class<?>... interfaces) {
	ProxyFactory pf = new ProxyFactory(target);
	if (interfaces.length > 1 || interfaces[0].isInterface()) {
		pf.setInterfaces(interfaces);
	}
	else {
		pf.setProxyTargetClass(true);
	}

	// Required everywhere we use AspectJ proxies
	pf.addAdvice(ExposeInvocationInterceptor.INSTANCE);

	for (Object a : advisors) {
		pf.addAdvisor((Advisor) a);
	}

	pf.setExposeProxy(true);
	return pf.getProxy();
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:20,代码来源:AbstractAspectJAdvisorFactoryTests.java

示例6: testAdvice

import org.springframework.aop.framework.ProxyFactory; //导入方法依赖的package包/类
private void testAdvice(Advisor advisor, LogUserAdvice logAdvice, TestService target, String message,
		boolean proxyTargetClass) throws Exception {

	logAdvice.reset();

	ProxyFactory factory = new ProxyFactory(target);
	factory.setProxyTargetClass(proxyTargetClass);
	factory.addAdvisor(advisor);
	TestService bean = (TestService) factory.getProxy();

	assertEquals(0, logAdvice.getCountThrows());
	try {
		bean.sayHello();
		fail("Expected exception");
	} catch (TestException e) {
		assertEquals(message, e.getMessage());
	}
	assertEquals(1, logAdvice.getCountThrows());
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:20,代码来源:TrickyAspectJPointcutExpressionTests.java

示例7: createRefreshableProxy

import org.springframework.aop.framework.ProxyFactory; //导入方法依赖的package包/类
/**
 * Create a refreshable proxy for the given AOP TargetSource.
 * @param ts the refreshable TargetSource
 * @param interfaces the proxy interfaces (may be {@code null} to
 * indicate proxying of all interfaces implemented by the target class)
 * @return the generated proxy
 * @see RefreshableScriptTargetSource
 */
protected Object createRefreshableProxy(TargetSource ts, Class<?>[] interfaces, boolean proxyTargetClass) {
	ProxyFactory proxyFactory = new ProxyFactory();
	proxyFactory.setTargetSource(ts);
	ClassLoader classLoader = this.beanClassLoader;

	if (interfaces == null) {
		interfaces = ClassUtils.getAllInterfacesForClass(ts.getTargetClass(), this.beanClassLoader);
	}
	proxyFactory.setInterfaces(interfaces);
	if (proxyTargetClass) {
		classLoader = null;  // force use of Class.getClassLoader()
		proxyFactory.setProxyTargetClass(true);
	}

	DelegatingIntroductionInterceptor introduction = new DelegatingIntroductionInterceptor(ts);
	introduction.suppressInterface(TargetSource.class);
	proxyFactory.addAdvice(introduction);

	return proxyFactory.getProxy(classLoader);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:29,代码来源:ScriptFactoryPostProcessor.java

示例8: testAdvice

import org.springframework.aop.framework.ProxyFactory; //导入方法依赖的package包/类
private void testAdvice(Advisor advisor, LogUserAdvice logAdvice, TestService target, String message,
		boolean proxyTargetClass) throws Exception {

	logAdvice.reset();

	ProxyFactory factory = new ProxyFactory(target);
	factory.setProxyTargetClass(proxyTargetClass);
	factory.addAdvisor(advisor);
	TestService bean = (TestService) factory.getProxy();

	assertEquals(0, logAdvice.getCountThrows());
	try {
		bean.sayHello();
		fail("Expected exception");
	}
	catch (TestException ex) {
		assertEquals(message, ex.getMessage());
	}
	assertEquals(1, logAdvice.getCountThrows());
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:21,代码来源:GroovyAspectTests.java

示例9: interceptorWithCglibProxy

import org.springframework.aop.framework.ProxyFactory; //导入方法依赖的package包/类
@Test
public void interceptorWithCglibProxy() throws Exception {
	final Object realObject = new Object();
	ProxyFactory proxyFactory = new ProxyFactory();
	proxyFactory.setTarget(realObject);
	proxyFactory.setProxyTargetClass(true);
	final Object proxy = proxyFactory.getProxy();

	ScopedObject scoped = new ScopedObject() {
		@Override
		public Object getTargetObject() {
			return proxy;
		}
		@Override
		public void removeFromScope() {
			// do nothing
		}
	};

	assertEquals(realObject.getClass().getName(), interceptor.getEntityName(scoped));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:22,代码来源:ScopedBeanInterceptorTests.java

示例10: transactionAttributeDeclaredOnCglibClassMethod

import org.springframework.aop.framework.ProxyFactory; //导入方法依赖的package包/类
/**
 * Test the important case where the invocation is on a proxied interface method
 * but the attribute is defined on the target class.
 */
@Test
public void transactionAttributeDeclaredOnCglibClassMethod() throws Exception {
	Method classMethod = ITestBean.class.getMethod("getAge");
	TestBean1 tb = new TestBean1();
	ProxyFactory pf = new ProxyFactory(tb);
	pf.setProxyTargetClass(true);
	Object proxy = pf.getProxy();

	AnnotationTransactionAttributeSource atas = new AnnotationTransactionAttributeSource();
	TransactionAttribute actual = atas.getTransactionAttribute(classMethod, proxy.getClass());

	RuleBasedTransactionAttribute rbta = new RuleBasedTransactionAttribute();
	rbta.getRollbackRules().add(new RollbackRuleAttribute(Exception.class));
	assertEquals(rbta.getRollbackRules(), ((RuleBasedTransactionAttribute) actual).getRollbackRules());
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:20,代码来源:AnnotationTransactionAttributeSourceTests.java

示例11: parameterAnnotationWithCglibProxy

import org.springframework.aop.framework.ProxyFactory; //导入方法依赖的package包/类
@Test
public void parameterAnnotationWithCglibProxy() throws JMSException {
	ProxyFactory pf = new ProxyFactory(sample);
	pf.setProxyTargetClass(true);
	listener = (JmsEndpointSampleBean) pf.getProxy();

	containerFactory.setMessageConverter(new UpperCaseMessageConverter());

	MethodJmsListenerEndpoint endpoint = createDefaultMethodJmsEndpoint(
			JmsEndpointSampleBean.class, "handleIt", String.class, String.class);
	Message message = new StubTextMessage("foo-bar");
	message.setStringProperty("my-header", "my-value");

	invokeListener(endpoint, message);
	assertListenerMethodInvocation("handleIt");
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:17,代码来源:JmsListenerContainerFactoryIntegrationTests.java

示例12: postProcessAfterInitialization

import org.springframework.aop.framework.ProxyFactory; //导入方法依赖的package包/类
@Override
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
    if (bean instanceof DataSource && !getDataSourceDecoratorProperties().getExcludeBeans().contains(beanName)) {
        DataSource dataSource = (DataSource) bean;
        DataSource decoratedDataSource = dataSource;
        Map<String, DataSourceDecorator> decorators = new LinkedHashMap<>();
        applicationContext.getBeansOfType(DataSourceDecorator.class)
                .entrySet()
                .stream()
                .sorted(Entry.comparingByValue(AnnotationAwareOrderComparator.INSTANCE))
                .forEach(entry -> decorators.put(entry.getKey(), entry.getValue()));
        List<DataSourceDecorationStage> decoratedDataSourceChainEntries = new ArrayList<>();
        for (Entry<String, DataSourceDecorator> decoratorEntry : decorators.entrySet()) {
            String decoratorBeanName = decoratorEntry.getKey();
            DataSourceDecorator decorator = decoratorEntry.getValue();

            DataSource dataSourceBeforeDecorating = decoratedDataSource;
            decoratedDataSource = Objects.requireNonNull(decorator.decorate(beanName, decoratedDataSource),
                    "DataSourceDecorator (" + decoratorBeanName + ", " + decorator + ") should not return null");

            if (dataSourceBeforeDecorating != decoratedDataSource) {
                decoratedDataSourceChainEntries.add(0, new DataSourceDecorationStage(decoratorBeanName, decorator, decoratedDataSource));
            }
        }
        if (dataSource != decoratedDataSource) {
            ProxyFactory factory = new ProxyFactory(bean);
            factory.setProxyTargetClass(true);
            factory.addInterface(DecoratedDataSource.class);
            factory.addAdvice(new DataSourceDecoratorInterceptor(beanName, dataSource, decoratedDataSource, decoratedDataSourceChainEntries));
            return factory.getProxy();
        }
    }
    return bean;
}
 
开发者ID:gavlyukovskiy,项目名称:spring-boot-data-source-decorator,代码行数:35,代码来源:DataSourceDecoratorBeanPostProcessor.java

示例13: createProxy

import org.springframework.aop.framework.ProxyFactory; //导入方法依赖的package包/类
private Object createProxy(final Class<?> clazz, Advice cardinalityInterceptor) {
	ProxyFactory factory = new ProxyFactory();
	factory.setProxyTargetClass(true);
	factory.setOptimize(true);
	factory.setTargetClass(clazz);

	factory.addAdvice(cardinalityInterceptor);
	factory.setFrozen(true);

	return factory.getProxy(ProxyFactory.class.getClassLoader());
}
 
开发者ID:eclipse,项目名称:gemini.blueprint,代码行数:12,代码来源:ServiceProxyTst.java

示例14: tstProxyCreation

import org.springframework.aop.framework.ProxyFactory; //导入方法依赖的package包/类
public void tstProxyCreation() throws Exception {
	ProxyFactory pf = new ProxyFactory();
	pf.setInterfaces(new Class<?>[] { Serializable.class, Comparable.class });
	//pf.setTargetClass(Number.class);
	pf.setProxyTargetClass(true);
	Object proxy = pf.getProxy();
	System.out.println(ObjectUtils.nullSafeToString(ClassUtils.getAllInterfaces(proxy)));
	assertTrue(proxy instanceof Number);
}
 
开发者ID:eclipse,项目名称:gemini.blueprint,代码行数:10,代码来源:OsgiServiceUtilsTest.java

示例15: createProxy

import org.springframework.aop.framework.ProxyFactory; //导入方法依赖的package包/类
/**
 * Create an AOP proxy for the given bean.
 * @param beanClass the class of the bean
 * @param beanName the name of the bean
 * @param specificInterceptors the set of interceptors that is
 * specific to this bean (may be empty, but not null)
 * @param targetSource the TargetSource for the proxy,
 * already pre-configured to access the bean
 * @return the AOP proxy for the bean
 * @see #buildAdvisors
 */
protected Object createProxy(
		Class<?> beanClass, String beanName, Object[] specificInterceptors, TargetSource targetSource) {

	ProxyFactory proxyFactory = new ProxyFactory();
	// Copy our properties (proxyTargetClass etc) inherited from ProxyConfig.
	proxyFactory.copyFrom(this);

	if (!proxyFactory.isProxyTargetClass()) {
		if (shouldProxyTargetClass(beanClass, beanName)) {
			proxyFactory.setProxyTargetClass(true);
		}
		else {
			evaluateProxyInterfaces(beanClass, proxyFactory);
		}
	}

	Advisor[] advisors = buildAdvisors(beanName, specificInterceptors);
	for (Advisor advisor : advisors) {
		proxyFactory.addAdvisor(advisor);
	}

	proxyFactory.setTargetSource(targetSource);
	customizeProxyFactory(proxyFactory);

	proxyFactory.setFrozen(this.freezeProxy);
	if (advisorsPreFiltered()) {
		proxyFactory.setPreFiltered(true);
	}

	return proxyFactory.getProxy(this.proxyClassLoader);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:43,代码来源:AbstractAutoProxyCreator.java


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