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.jcache.config; 018 019import org.springframework.beans.factory.config.BeanDefinition; 020import org.springframework.cache.config.CacheManagementConfigUtils; 021import org.springframework.cache.jcache.interceptor.BeanFactoryJCacheOperationSourceAdvisor; 022import org.springframework.cache.jcache.interceptor.JCacheInterceptor; 023import org.springframework.context.annotation.Bean; 024import org.springframework.context.annotation.Configuration; 025import org.springframework.context.annotation.Role; 026 027/** 028 * {@code @Configuration} class that registers the Spring infrastructure beans necessary 029 * to enable proxy-based annotation-driven JSR-107 cache management. 030 * 031 * <p>Can safely be used alongside Spring's caching support. 032 * 033 * @author Stephane Nicoll 034 * @author Juergen Hoeller 035 * @since 4.1 036 * @see org.springframework.cache.annotation.EnableCaching 037 * @see org.springframework.cache.annotation.CachingConfigurationSelector 038 */ 039@Configuration 040@Role(BeanDefinition.ROLE_INFRASTRUCTURE) 041public class ProxyJCacheConfiguration extends AbstractJCacheConfiguration { 042 043 @Bean(name = CacheManagementConfigUtils.JCACHE_ADVISOR_BEAN_NAME) 044 @Role(BeanDefinition.ROLE_INFRASTRUCTURE) 045 public BeanFactoryJCacheOperationSourceAdvisor cacheAdvisor() { 046 BeanFactoryJCacheOperationSourceAdvisor advisor = 047 new BeanFactoryJCacheOperationSourceAdvisor(); 048 advisor.setCacheOperationSource(cacheOperationSource()); 049 advisor.setAdvice(cacheInterceptor()); 050 if (this.enableCaching != null) { 051 advisor.setOrder(this.enableCaching.<Integer>getNumber("order")); 052 } 053 return advisor; 054 } 055 056 @Bean(name = "jCacheInterceptor") 057 @Role(BeanDefinition.ROLE_INFRASTRUCTURE) 058 public JCacheInterceptor cacheInterceptor() { 059 JCacheInterceptor interceptor = new JCacheInterceptor(this.errorHandler); 060 interceptor.setCacheOperationSource(cacheOperationSource()); 061 return interceptor; 062 } 063 064}