• 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏吧

Java BeanFactoryCacheOperationSourceAdvisor类的典型用法和代码示例

java 2次浏览

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

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

示例1: configureAutoProxyCreator

点赞 3

import org.springframework.cache.interceptor.BeanFactoryCacheOperationSourceAdvisor; //导入依赖的package包/类
public static void configureAutoProxyCreator(Element element, ParserContext parserContext) {
	AopNamespaceUtils.registerAutoProxyCreatorIfNecessary(parserContext, element);

	if (!parserContext.getRegistry().containsBeanDefinition(CACHE_ADVISOR_BEAN_NAME)) {
		Object eleSource = parserContext.extractSource(element);

		// Create the CacheOperationSource definition.
		RootBeanDefinition sourceDef = new RootBeanDefinition(AnnotationCacheOperationSource.class);
		sourceDef.setSource(eleSource);
		sourceDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
		String sourceName = parserContext.getReaderContext().registerWithGeneratedName(sourceDef);

		// Create the CacheInterceptor definition.
		RootBeanDefinition interceptorDef = new RootBeanDefinition(CacheInterceptor.class);
		interceptorDef.setSource(eleSource);
		interceptorDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
		parseCacheManagerProperty(element, interceptorDef);
		CacheNamespaceHandler.parseKeyGenerator(element, interceptorDef);
		interceptorDef.getPropertyValues().add("cacheOperationSources", new RuntimeBeanReference(sourceName));
		String interceptorName = parserContext.getReaderContext().registerWithGeneratedName(interceptorDef);

		// Create the CacheAdvisor definition.
		RootBeanDefinition advisorDef = new RootBeanDefinition(BeanFactoryCacheOperationSourceAdvisor.class);
		advisorDef.setSource(eleSource);
		advisorDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
		advisorDef.getPropertyValues().add("cacheOperationSource", new RuntimeBeanReference(sourceName));
		advisorDef.getPropertyValues().add("adviceBeanName", interceptorName);
		if (element.hasAttribute("order")) {
			advisorDef.getPropertyValues().add("order", element.getAttribute("order"));
		}
		parserContext.getRegistry().registerBeanDefinition(CACHE_ADVISOR_BEAN_NAME, advisorDef);

		CompositeComponentDefinition compositeDef = new CompositeComponentDefinition(element.getTagName(),
				eleSource);
		compositeDef.addNestedComponent(new BeanComponentDefinition(sourceDef, sourceName));
		compositeDef.addNestedComponent(new BeanComponentDefinition(interceptorDef, interceptorName));
		compositeDef.addNestedComponent(new BeanComponentDefinition(advisorDef, CACHE_ADVISOR_BEAN_NAME));
		parserContext.registerComponent(compositeDef);
	}
}
 

开发者ID:deathspeeder,
项目名称:class-guard,
代码行数:41,
代码来源:AnnotationDrivenCacheBeanDefinitionParser.java

示例2: teamServiceIsAdvisedForCaching

点赞 3

import org.springframework.cache.interceptor.BeanFactoryCacheOperationSourceAdvisor; //导入依赖的package包/类
/**
 * Check that {@link #teamService} is advised for caching and that all methods
 * relating to published posts have the {@link Cacheable} annotation. Note that while
 * more extensive mocking and testing through {@code MockMvc} etc is possible, this
 * approach is less fragile and much more concise while still being likely to catch
 * configuration errors.
 */
@Test
public void teamServiceIsAdvisedForCaching() {
    assertThat("TeamService is not advised as expected", teamService, instanceOf(Advised.class));
    boolean hasCachingAdvisor = false;
    for (Advisor advisor : ((Advised) teamService).getAdvisors()) {
        if (advisor instanceof BeanFactoryCacheOperationSourceAdvisor) {
            hasCachingAdvisor = true;
            break;
        }
    }
    assertTrue("TeamService is advised, but does not have caching advisor", hasCachingAdvisor);
    ReflectionUtils.doWithMethods(TeamService.class, method -> {
        Cacheable cacheable = AnnotationUtils.findAnnotation(method, Cacheable.class);
        String methodName = method.getName();
        if (methodName.equals("fetchMemberProfileUsername")) {
            assertNotNull("Method " + methodName + " was expected to have Cacheable annotation.", cacheable);
            String[] cacheName = cacheable.value();
            assertThat(cacheName[0], equalTo(TeamService.CACHE_NAME));
        }
        else {
            assertNull("Method " + methodName + " was not expected to have Cacheable annotation.", cacheable);
        }
    });
}
 

开发者ID:spring-io,
项目名称:sagan,
代码行数:32,
代码来源:TeamServiceCachingTests.java

示例3: cacheAdvisor

点赞 2

import org.springframework.cache.interceptor.BeanFactoryCacheOperationSourceAdvisor; //导入依赖的package包/类
@Bean(name=AnnotationConfigUtils.CACHE_ADVISOR_BEAN_NAME)
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
public BeanFactoryCacheOperationSourceAdvisor cacheAdvisor() {
	BeanFactoryCacheOperationSourceAdvisor advisor =
		new BeanFactoryCacheOperationSourceAdvisor();
	advisor.setCacheOperationSource(cacheOperationSource());
	advisor.setAdvice(cacheInterceptor());
	advisor.setOrder(this.enableCaching.<Integer>getNumber("order"));
	return advisor;
}
 

开发者ID:lamsfoundation,
项目名称:lams,
代码行数:11,
代码来源:ProxyCachingConfiguration.java

示例4: cacheAdvisor

点赞 2

import org.springframework.cache.interceptor.BeanFactoryCacheOperationSourceAdvisor; //导入依赖的package包/类
@Bean(name = CacheManagementConfigUtils.CACHE_ADVISOR_BEAN_NAME)
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
public BeanFactoryCacheOperationSourceAdvisor cacheAdvisor() {
	BeanFactoryCacheOperationSourceAdvisor advisor =
			new BeanFactoryCacheOperationSourceAdvisor();
	advisor.setCacheOperationSource(cacheOperationSource());
	advisor.setAdvice(cacheInterceptor());
	advisor.setOrder(this.enableCaching.<Integer>getNumber("order"));
	return advisor;
}
 

开发者ID:langtianya,
项目名称:spring4-understanding,
代码行数:11,
代码来源:ProxyCachingConfiguration.java

示例5: registerCacheAdvisor

点赞 2

import org.springframework.cache.interceptor.BeanFactoryCacheOperationSourceAdvisor; //导入依赖的package包/类
private static void registerCacheAdvisor(Element element, ParserContext parserContext) {
	if (!parserContext.getRegistry().containsBeanDefinition(CacheManagementConfigUtils.CACHE_ADVISOR_BEAN_NAME)) {
		Object eleSource = parserContext.extractSource(element);

		// Create the CacheOperationSource definition.
		RootBeanDefinition sourceDef = new RootBeanDefinition("org.springframework.cache.annotation.AnnotationCacheOperationSource");
		sourceDef.setSource(eleSource);
		sourceDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
		String sourceName = parserContext.getReaderContext().registerWithGeneratedName(sourceDef);

		// Create the CacheInterceptor definition.
		RootBeanDefinition interceptorDef = new RootBeanDefinition(CacheInterceptor.class);
		interceptorDef.setSource(eleSource);
		interceptorDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
		parseCacheResolution(element, interceptorDef, false);
		parseErrorHandler(element, interceptorDef);
		CacheNamespaceHandler.parseKeyGenerator(element, interceptorDef);
		interceptorDef.getPropertyValues().add("cacheOperationSources", new RuntimeBeanReference(sourceName));
		String interceptorName = parserContext.getReaderContext().registerWithGeneratedName(interceptorDef);

		// Create the CacheAdvisor definition.
		RootBeanDefinition advisorDef = new RootBeanDefinition(BeanFactoryCacheOperationSourceAdvisor.class);
		advisorDef.setSource(eleSource);
		advisorDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
		advisorDef.getPropertyValues().add("cacheOperationSource", new RuntimeBeanReference(sourceName));
		advisorDef.getPropertyValues().add("adviceBeanName", interceptorName);
		if (element.hasAttribute("order")) {
			advisorDef.getPropertyValues().add("order", element.getAttribute("order"));
		}
		parserContext.getRegistry().registerBeanDefinition(CacheManagementConfigUtils.CACHE_ADVISOR_BEAN_NAME, advisorDef);

		CompositeComponentDefinition compositeDef = new CompositeComponentDefinition(element.getTagName(), eleSource);
		compositeDef.addNestedComponent(new BeanComponentDefinition(sourceDef, sourceName));
		compositeDef.addNestedComponent(new BeanComponentDefinition(interceptorDef, interceptorName));
		compositeDef.addNestedComponent(new BeanComponentDefinition(advisorDef, CacheManagementConfigUtils.CACHE_ADVISOR_BEAN_NAME));
		parserContext.registerComponent(compositeDef);
	}
}
 

开发者ID:langtianya,
项目名称:spring4-understanding,
代码行数:39,
代码来源:AnnotationDrivenCacheBeanDefinitionParser.java

示例6: assertCacheProxying

点赞 2

import org.springframework.cache.interceptor.BeanFactoryCacheOperationSourceAdvisor; //导入依赖的package包/类
private void assertCacheProxying(AnnotationConfigApplicationContext ctx) {
	FooRepository repo = ctx.getBean(FooRepository.class);

	boolean isCacheProxy = false;
	if (AopUtils.isAopProxy(repo)) {
		for (Advisor advisor : ((Advised)repo).getAdvisors()) {
			if (advisor instanceof BeanFactoryCacheOperationSourceAdvisor) {
				isCacheProxy = true;
				break;
			}
		}
	}
	assertTrue("FooRepository is not a cache proxy", isCacheProxy);
}
 

开发者ID:langtianya,
项目名称:spring4-understanding,
代码行数:15,
代码来源:EnableCachingIntegrationTests.java


版权声明:本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系管理员进行删除。
喜欢 (0)