12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- package com.jiayue.ipfcst.spare2;
- import io.netty.util.ResourceLeakDetector;
- import lombok.extern.slf4j.Slf4j;
- import net.sf.ehcache.CacheManager;
- import org.apache.velocity.app.Velocity;
- import org.apache.velocity.app.VelocityEngine;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.boot.autoconfigure.SpringBootApplication;
- import org.springframework.boot.builder.SpringApplicationBuilder;
- import org.springframework.cache.annotation.EnableCaching;
- import org.springframework.cache.ehcache.EhCacheCacheManager;
- import org.springframework.cache.ehcache.EhCacheManagerFactoryBean;
- import org.springframework.context.annotation.Bean;
- import org.springframework.context.annotation.Configuration;
- import org.springframework.core.env.Environment;
- import org.springframework.core.io.ClassPathResource;
- import org.springframework.scheduling.annotation.EnableScheduling;
- import java.util.Properties;
- import java.util.TimeZone;
- /**
- * 启动类
- *
- * @author zzy
- * @version 1.0
- * @since 2019/7/22 9:05
- */
- @Configuration
- @SpringBootApplication
- @Slf4j
- @EnableScheduling
- @EnableCaching
- public class Spare2Application {
- private final Environment environment;
- @Autowired
- public Spare2Application(Environment environment) {
- this.environment = environment;
- }
- public static void main(String[] args) {
- TimeZone.setDefault(TimeZone.getTimeZone("GMT+8"));
- ResourceLeakDetector.setLevel(ResourceLeakDetector.Level.ADVANCED);
- //变更配置文件读取位置启动
- new SpringApplicationBuilder(Spare2Application.class).run(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;
- }
- /**
- * 上报文件模板引擎
- *
- * @return 返回模板引擎
- */
- @Bean
- public VelocityEngine velocityEngine() {
- VelocityEngine ve = new VelocityEngine();
- Properties properties = new Properties();
- //设置velocity资源加载方式为file
- properties.setProperty("resource.loader", "file");
- //设置velocity资源加载方式为file时的处理类
- properties.setProperty("file.resource.loader.class", "org.apache.velocity.runtime.resource.loader.FileResourceLoader");
- properties.setProperty(Velocity.FILE_RESOURCE_LOADER_PATH, "");
- properties.setProperty(Velocity.ENCODING_DEFAULT, "UTF-8");
- properties.setProperty(Velocity.INPUT_ENCODING, "UTF-8");
- properties.setProperty(Velocity.OUTPUT_ENCODING, "UTF-8");
- ve.init(properties);
- return ve;
- }
- }
|