package com.jiayue.insu.inclientqn;

import net.sf.ehcache.CacheManager;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.cache.ehcache.EhCacheCacheManager;
import org.springframework.cache.ehcache.EhCacheManagerFactoryBean;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.context.annotation.Bean;
import org.springframework.core.io.ClassPathResource;

@SpringBootApplication
@EnableDiscoveryClient
@EnableCaching
public class InClientQnApplication {
    public static void main(String[] args) {
        SpringApplication.run(InClientQnApplication.class, args);
    }


    /**
     * ecache缓存对象获取
     */
    @Bean
    public EhCacheCacheManager cacheManager(CacheManager cacheManagerFactory) {
        EhCacheCacheManager ehCacheCacheManager = new EhCacheCacheManager();
        ehCacheCacheManager.setCacheManager(cacheManagerFactory);
        return ehCacheCacheManager;
    }

    /**
     * ecache缓存配置加载
     */
    @Bean
    public EhCacheManagerFactoryBean cacheManagerFactory() {
        EhCacheManagerFactoryBean ehCacheManagerFactoryBean = new EhCacheManagerFactoryBean();
        ehCacheManagerFactoryBean.setConfigLocation(new ClassPathResource("ehcache-setting.xml"));
        return ehCacheManagerFactoryBean;
    }

}
