001/* 002 * Copyright 2012-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 * http://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.boot.actuate.autoconfigure.cache; 018 019import java.util.LinkedHashMap; 020import java.util.Map; 021 022import org.springframework.beans.factory.ObjectProvider; 023import org.springframework.boot.actuate.autoconfigure.endpoint.condition.ConditionalOnEnabledEndpoint; 024import org.springframework.boot.actuate.cache.CachesEndpoint; 025import org.springframework.boot.actuate.cache.CachesEndpointWebExtension; 026import org.springframework.boot.autoconfigure.AutoConfigureAfter; 027import org.springframework.boot.autoconfigure.EnableAutoConfiguration; 028import org.springframework.boot.autoconfigure.cache.CacheAutoConfiguration; 029import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; 030import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; 031import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; 032import org.springframework.cache.CacheManager; 033import org.springframework.context.annotation.Bean; 034import org.springframework.context.annotation.Configuration; 035 036/** 037 * {@link EnableAutoConfiguration Auto-configuration} for {@link CachesEndpoint}. 038 * 039 * @author Johannes Edmeier 040 * @author Stephane Nicoll 041 * @since 2.1.0 042 */ 043@Configuration 044@ConditionalOnClass(CacheManager.class) 045@AutoConfigureAfter(CacheAutoConfiguration.class) 046public class CachesEndpointAutoConfiguration { 047 048 @Bean 049 @ConditionalOnMissingBean 050 @ConditionalOnEnabledEndpoint 051 public CachesEndpoint cachesEndpoint( 052 ObjectProvider<Map<String, CacheManager>> cacheManagers) { 053 return new CachesEndpoint(cacheManagers.getIfAvailable(LinkedHashMap::new)); 054 } 055 056 @Bean 057 @ConditionalOnMissingBean 058 @ConditionalOnEnabledEndpoint 059 @ConditionalOnBean(CachesEndpoint.class) 060 public CachesEndpointWebExtension cachesEndpointWebExtension( 061 CachesEndpoint cachesEndpoint) { 062 return new CachesEndpointWebExtension(cachesEndpoint); 063 } 064 065}