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


Java ProxyFactoryBean类代码示例

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


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

示例1: installAclPredicateTargetSource

import org.springframework.aop.framework.ProxyFactoryBean; //导入依赖的package包/类
private AclPredicateTargetSource installAclPredicateTargetSource() {
  synchronized (cachedCriteriaQuery) {
    Predicate restriction = cachedCriteriaQuery.getRestriction();

    if (restriction instanceof Advised) {
      Advised advised = (Advised) restriction;
      if (advised.getTargetSource() instanceof AclPredicateTargetSource) {
        return (AclPredicateTargetSource) advised.getTargetSource();
      }
    }

    AclPredicateTargetSource targetSource = new AclPredicateTargetSource(em.getCriteriaBuilder(), restriction);
    ProxyFactoryBean factoryBean = new ProxyFactoryBean();
    factoryBean.setTargetSource(targetSource);
    factoryBean.setAutodetectInterfaces(true);
    Predicate enhancedPredicate = (Predicate) factoryBean.getObject();
    logger.debug("ACL Jpa Specification target source initialized for criteria {}", cachedCriteriaQuery);

    // install proxy inside criteria
    cachedCriteriaQuery.where(enhancedPredicate);
    return targetSource;
  }
}
 
开发者ID:lordlothar99,项目名称:strategy-spring-security-acl,代码行数:24,代码来源:AclJpaQuery.java

示例2: upgradeAllOrNothing

import org.springframework.aop.framework.ProxyFactoryBean; //导入依赖的package包/类
@Test
@DirtiesContext
public void upgradeAllOrNothing() throws Exception {
	TestUserService testUserService = new TestUserService(users.get(3).getId());
	testUserService.setUserDao(this.userDao);
	testUserService.setMailSender(mailSender);
	
	ProxyFactoryBean txProxyFactoryBean = context.getBean("&userService", ProxyFactoryBean.class);
	txProxyFactoryBean.setTarget(testUserService);
	
	UserService txUserService = (UserService) txProxyFactoryBean.getObject();

	userDao.deleteAll();

	for (User user : users)
		userDao.add(user);

	try {
		txUserService.upgradeLevels();
		fail("TestUserServiceException expected");
	} catch (TestUserServiceException e) {
	}
	checkLevel(users.get(1), false); // 오류 이전에 Update 한 사용자의 Level이 바뀌었나 확인
}
 
开发者ID:UCJung,项目名称:javalab,代码行数:25,代码来源:UserServiceTest.java

示例3: proxyFactoryBean

import org.springframework.aop.framework.ProxyFactoryBean; //导入依赖的package包/类
@Test
public void proxyFactoryBean() {
	ProxyFactoryBean pfBean = new ProxyFactoryBean();
	pfBean.setTarget(new HelloTarget());
	pfBean.addAdvice(new UppercaseAdvice());
	pfBean.setInterfaces(new Class[] { Hello.class }); // 생략해도 됨.

	Hello proxiedHandler = (Hello) pfBean.getObject();

	assertThat(proxiedHandler.sayHello("JUNG"), is("HELLO JUNG"));
	assertThat(proxiedHandler.sayHi("JUNG"), is("HI JUNG"));
	assertThat(proxiedHandler.sayThankYou("JUNG"), is("THANK YOU JUNG"));
}
 
开发者ID:UCJung,项目名称:javalab,代码行数:14,代码来源:HelloTest.java

示例4: pointcutAdvisor

import org.springframework.aop.framework.ProxyFactoryBean; //导入依赖的package包/类
@Test
public void pointcutAdvisor() {
	ProxyFactoryBean pfBean = new ProxyFactoryBean();
	pfBean.setTarget(new HelloTarget());

	NameMatchMethodPointcut pointcut = new NameMatchMethodPointcut();
	pointcut.setMappedName("sayH*");

	pfBean.addAdvisor(new DefaultPointcutAdvisor(pointcut,
			new UppercaseAdvice()));

	Hello proxiedHello = (Hello) pfBean.getObject();

	assertThat(proxiedHello.sayHello("Jung"), is("HELLO JUNG"));
	assertThat(proxiedHello.sayHi("Jung"), is("HI JUNG"));
	assertThat(proxiedHello.sayThankYou("Jung"), is("Thank you Jung"));
}
 
开发者ID:UCJung,项目名称:javalab,代码行数:18,代码来源:HelloTest.java

示例5: checkAdvice

import org.springframework.aop.framework.ProxyFactoryBean; //导入依赖的package包/类
private void checkAdvice(Object target,
		Pointcut pointcut, boolean adviced) {
	ProxyFactoryBean pfBean = new ProxyFactoryBean();
	pfBean.setTarget(target);
	pfBean.addAdvisor(new DefaultPointcutAdvisor(pointcut, new UppercaseAdvice()));
	Hello proxiedHello = (Hello)pfBean.getObject();
	
	if (adviced) {
		assertThat(proxiedHello.sayHello("Jung"), is("HELLO JUNG"));
		assertThat(proxiedHello.sayHi("Jung"), is("HI JUNG"));
		assertThat(proxiedHello.sayThankYou("Jung"), is("Thank you Jung"));			
	}
	else {
		assertThat(proxiedHello.sayHello("Jung"), is("Hello Jung"));
		assertThat(proxiedHello.sayHi("Jung"), is("Hi Jung"));
		assertThat(proxiedHello.sayThankYou("Jung"), is("Thank you Jung"));			
	}
}
 
开发者ID:UCJung,项目名称:javalab,代码行数:19,代码来源:HelloTest.java

示例6: environmentForImage

import org.springframework.aop.framework.ProxyFactoryBean; //导入依赖的package包/类
private Environment environmentForImage(int maxWidth, boolean invert) {
	Map<String, Object> specification = new HashMap<>();
	specification.put("banner.image.width", maxWidth);
	specification.put("banner.image.invert", invert);
	ProxyFactoryBean proxyFactoryBean = new ProxyFactoryBean();
	proxyFactoryBean.setInterfaces(Environment.class);
	proxyFactoryBean.addAdvice((MethodInterceptor) invocation -> {
		String containsProperty = "containsProperty";
		String getProperty = "getProperty";
		List<String> toHandle = Arrays.asList(containsProperty, getProperty);
		String methodName = invocation.getMethod().getName();
		if (toHandle.contains(methodName)) {
			String key = String.class.cast(invocation.getArguments()[0]);
			if (methodName.equals(containsProperty)) {
				return (specification.containsKey(key) || this.environment.containsProperty(key));
			}
			if (methodName.equals(getProperty)) {
				return specification.getOrDefault(key, this.environment.getProperty(key));
			}
		}
		return invocation.getMethod().invoke(this.environment, invocation.getArguments());
	});
	return Environment.class.cast(proxyFactoryBean.getObject());
}
 
开发者ID:joshlong,项目名称:bootiful-banners,代码行数:25,代码来源:BootifulBannersServiceApplication.java

示例7: lookup

import org.springframework.aop.framework.ProxyFactoryBean; //导入依赖的package包/类
public <T> T lookup(String serviceName, Class<T> serviceInterface) {
    log.debug("Looking up service '{}' with interface '{}'", serviceName, serviceInterface.getSimpleName());

    String importProxyName = serviceName + BEAN_DEF_SUFFIX;

    if (!context.containsBean(importProxyName)) {
        RootBeanDefinition proxyBeanDef = new RootBeanDefinition(ProxyFactoryBean.class);

        proxyBeanDef.setRole(ROLE_INFRASTRUCTURE);
        proxyBeanDef.getPropertyValues().add("targetSource",
                new LookupTargetSource(serviceName, serviceInterface, serviceName + TARGET_SOURCE_SUFFIX, context));

        ((BeanDefinitionRegistry) beanFactory).registerBeanDefinition(importProxyName, proxyBeanDef);
    }

    return context.getBean(importProxyName, serviceInterface);
}
 
开发者ID:jirutka,项目名称:spring-modular,代码行数:18,代码来源:ContextParentBean.java

示例8: createProxyFactoryBean

import org.springframework.aop.framework.ProxyFactoryBean; //导入依赖的package包/类
private ProxyFactoryBean createProxyFactoryBean(IService rawService, boolean proxyTargetClass) throws ClassNotFoundException {
	final ProxyFactoryBean proxyFactoryBean = new ProxyFactoryBean();
	proxyFactoryBean.setProxyInterfaces(new Class<?>[]{IService.class});
	proxyFactoryBean.setTarget(rawService);
	proxyFactoryBean.setProxyTargetClass(proxyTargetClass);
	return proxyFactoryBean;
}
 
开发者ID:pchudzik,项目名称:springmock,代码行数:8,代码来源:ToSpyReplacingProcessorTest.java

示例9: proxyAdvice

import org.springframework.aop.framework.ProxyFactoryBean; //导入依赖的package包/类
private static <T> T proxyAdvice(T t, Advice methodInterceptor) {
    ProxyFactoryBean proxyFactoryBean = new ProxyFactoryBean();
    proxyFactoryBean.setTargetClass(t.getClass());
    proxyFactoryBean.setTarget(t);
    proxyFactoryBean.addAdvice(methodInterceptor);
    return (T) proxyFactoryBean.getObject();
}
 
开发者ID:maniaclee,项目名称:shardy,代码行数:8,代码来源:ShardSqlSessionFactoryBean.java

示例10: proxyAdvice

import org.springframework.aop.framework.ProxyFactoryBean; //导入依赖的package包/类
public static <T> T proxyAdvice(T t, Advice methodInterceptor) {
    ProxyFactoryBean proxyFactoryBean = new ProxyFactoryBean();
    proxyFactoryBean.setTargetClass(t.getClass());
    proxyFactoryBean.setTarget(t);
    proxyFactoryBean.addAdvice(methodInterceptor);
    return (T) proxyFactoryBean.getObject();
}
 
开发者ID:maniaclee,项目名称:shardy,代码行数:8,代码来源:ProxyUtils.java

示例11: postProcessBeanFactory

import org.springframework.aop.framework.ProxyFactoryBean; //导入依赖的package包/类
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory)
		throws BeansException {
	logger.debug("................MiniDaoBeanFactory................ContextRefreshed...................");
	try {
		//循环传入的MiniDao配置
		for(String pack : packagesToScan){
			if(org.apache.commons.lang.StringUtils.isNotEmpty(pack)){
			   Set<Class<?>> classSet = PackagesToScanUtil.getClasses(pack);
			   for(Class<?> miniDaoClass : classSet){
				   if(miniDaoClass.isAnnotationPresent(MiniDao.class)){
					   //单独加载一个接口的代理类
					   ProxyFactoryBean proxyFactoryBean = new ProxyFactoryBean();
					   proxyFactoryBean.setBeanFactory(beanFactory);
					   proxyFactoryBean.setInterfaces(new Class[]{miniDaoClass});
					   proxyFactoryBean.setInterceptorNames(new String[]{"miniDaoHandler"});
					   String beanName = MiniDaoUtil.getFirstSmall(miniDaoClass.getSimpleName());
					   if(!beanFactory.containsBean(beanName)){
						   
						   //logger.info(".................MiniDaoBean.................init...................."+miniDaoClass.getName());
						   logger.info("MiniDao Interface [/"+miniDaoClass.getName()+"/] onto Spring Bean '"+beanName+"'");
						   beanFactory.registerSingleton(beanName,proxyFactoryBean.getObject());
					   }
				   }
			   }
			}
		}
	} catch (Exception e) {
		e.printStackTrace();
	}
}
 
开发者ID:East196,项目名称:maker,代码行数:31,代码来源:MiniDaoBeanFactory.java

示例12: amazonDynamoDbProxy

import org.springframework.aop.framework.ProxyFactoryBean; //导入依赖的package包/类
@Bean(name = "amazonDynamoDB")
public ProxyFactoryBean amazonDynamoDbProxy() {
    ProxyFactoryBean proxyFactoryBean = new ProxyFactoryBean();

    proxyFactoryBean.setTarget(amazonDynamoDB());
    proxyFactoryBean.setInterceptorNames("retryInterceptor");
    return proxyFactoryBean;
}
 
开发者ID:SungardAS,项目名称:enhanced-snapshots,代码行数:9,代码来源:AmazonConfigProvider.java

示例13: amazonEC2Proxy

import org.springframework.aop.framework.ProxyFactoryBean; //导入依赖的package包/类
@Bean
public ProxyFactoryBean amazonEC2Proxy() {
    ProxyFactoryBean proxyFactoryBean = new ProxyFactoryBean();

    proxyFactoryBean.setTarget(amazonEC2());
    proxyFactoryBean.setInterceptorNames("retryInterceptor");

    return proxyFactoryBean;
}
 
开发者ID:SungardAS,项目名称:enhanced-snapshots,代码行数:10,代码来源:AmazonConfigProvider.java

示例14: amazonS3Proxy

import org.springframework.aop.framework.ProxyFactoryBean; //导入依赖的package包/类
@Bean
public ProxyFactoryBean amazonS3Proxy() {
    ProxyFactoryBean proxyFactoryBean = new ProxyFactoryBean();

    proxyFactoryBean.setTarget(amazonS3());
    proxyFactoryBean.setInterceptorNames("retryInterceptor");

    return proxyFactoryBean;
}
 
开发者ID:SungardAS,项目名称:enhanced-snapshots,代码行数:10,代码来源:AmazonConfigProvider.java

示例15: amazonDynamoDbMapperProxy

import org.springframework.aop.framework.ProxyFactoryBean; //导入依赖的package包/类
@Bean (name = "amazonDynamoDbMapper")
public ProxyFactoryBean amazonDynamoDbMapperProxy() {
    ProxyFactoryBean proxyFactoryBean = new ProxyFactoryBean();

    proxyFactoryBean.setTarget(dynamoDBMapper());
    proxyFactoryBean.setInterceptorNames("retryInterceptor");

    return proxyFactoryBean;
}
 
开发者ID:SungardAS,项目名称:enhanced-snapshots,代码行数:10,代码来源:AmazonConfigProvider.java


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