001/* 002 * Copyright 2002-2018 the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * https://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package org.springframework.cache.aspectj; 018 019import org.springframework.beans.factory.config.BeanDefinition; 020import org.springframework.cache.annotation.AbstractCachingConfiguration; 021import org.springframework.cache.config.CacheManagementConfigUtils; 022import org.springframework.context.annotation.Bean; 023import org.springframework.context.annotation.Configuration; 024import org.springframework.context.annotation.Role; 025 026/** 027 * {@code @Configuration} class that registers the Spring infrastructure beans 028 * necessary to enable AspectJ-based annotation-driven cache management. 029 * 030 * @author Chris Beams 031 * @author Stephane Nicoll 032 * @since 3.1 033 * @see org.springframework.cache.annotation.EnableCaching 034 * @see org.springframework.cache.annotation.CachingConfigurationSelector 035 */ 036@Configuration 037@Role(BeanDefinition.ROLE_INFRASTRUCTURE) 038public class AspectJCachingConfiguration extends AbstractCachingConfiguration { 039 040 @Bean(name = CacheManagementConfigUtils.CACHE_ASPECT_BEAN_NAME) 041 @Role(BeanDefinition.ROLE_INFRASTRUCTURE) 042 public AnnotationCacheAspect cacheAspect() { 043 AnnotationCacheAspect cacheAspect = AnnotationCacheAspect.aspectOf(); 044 if (this.cacheResolver != null) { 045 cacheAspect.setCacheResolver(this.cacheResolver); 046 } 047 else if (this.cacheManager != null) { 048 cacheAspect.setCacheManager(this.cacheManager); 049 } 050 if (this.keyGenerator != null) { 051 cacheAspect.setKeyGenerator(this.keyGenerator); 052 } 053 if (this.errorHandler != null) { 054 cacheAspect.setErrorHandler(this.errorHandler); 055 } 056 return cacheAspect; 057 } 058 059}