| | |
| | | package com.ltkj.framework.config; |
| | | |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.cache.annotation.CachingConfigurerSupport; |
| | | import org.springframework.cache.annotation.EnableCaching; |
| | | import org.springframework.context.annotation.Bean; |
| | |
| | | @EnableCaching |
| | | @Slf4j |
| | | public class RedisConfig extends CachingConfigurerSupport { |
| | | |
| | | @Value ("${config.properties}") |
| | | private String url; |
| | | |
| | | @Value ("${config.path}") |
| | | private String path; |
| | | |
| | | @Bean |
| | | @SuppressWarnings(value = {"unchecked", "rawtypes"}) |
| | | public RedisTemplate<Object, Object> redisTemplate(RedisConnectionFactory connectionFactory) { |
| | | RedisTemplate<Object, Object> template = new RedisTemplate<>(); |
| | | template.setConnectionFactory(connectionFactory); |
| | | |
| | | FastJson2JsonRedisSerializer serializer = new FastJson2JsonRedisSerializer(Object.class); |
| | | |
| | | // 使用StringRedisSerializer来序列化和反序列化redis的key值 |
| | | template.setKeySerializer(new StringRedisSerializer()); |
| | | template.setValueSerializer(serializer); |
| | | |
| | | // Hash的key也采用StringRedisSerializer的序列化方式 |
| | | template.setHashKeySerializer(new StringRedisSerializer()); |
| | | template.setHashValueSerializer(serializer); |
| | | |
| | | template.afterPropertiesSet(); |
| | | return template; |
| | | } |
| | | |
| | | @Bean |
| | | public JedisPoolConfig jedisPoolConfig() { |
| | | JedisPoolConfig config = new JedisPoolConfig(); |
| | | // 设置JedisPoolConfig的相关参数,例如最大连接数、最大空闲时间等 |
| | | // config.setMinIdle(0); |
| | | // config.setMaxIdle(8); |
| | | // config.setMaxIdle(0); |
| | | // config.setMaxTotal(8); |
| | | // config.setTimeBetweenEvictionRunsMillis(10); |
| | | // config.setMaxWaitMillis(-1); |
| | | // config.setTestOnBorrow(true); |
| | | // config.setTestOnReturn(true); |
| | | return config; |
| | | } |
| | | @Bean |
| | |
| | | FileInputStream fis = null; |
| | | Properties props = new Properties(); |
| | | try { |
| | | fis = new FileInputStream("D:\\ltkjprojectconf\\config.properties"); |
| | | fis = new FileInputStream(url); |
| | | } catch (FileNotFoundException e) { |
| | | log.info("配置文件找不到 系统正在创建!"); |
| | | File f = new File("D:\\ltkjprojectconf"); |
| | | File f = new File(path); |
| | | if(!f.exists()){ |
| | | f.mkdirs(); |
| | | } |
| | | File file = new File("D:\\ltkjprojectconf\\config.properties"); |
| | | File file = new File(url); |
| | | try { |
| | | FileWriter fileWriter = new FileWriter(file); |
| | | fileWriter.write("ip = 你的主数据库连接ip地址\n"); |
| | |
| | | } |
| | | return factory; |
| | | } |
| | | @Bean |
| | | @SuppressWarnings(value = {"unchecked", "rawtypes"}) |
| | | public RedisTemplate<Object, Object> redisTemplate(RedisConnectionFactory connectionFactory) { |
| | | RedisTemplate<Object, Object> template = new RedisTemplate<>(); |
| | | template.setConnectionFactory(connectionFactory); |
| | | |
| | | FastJson2JsonRedisSerializer serializer = new FastJson2JsonRedisSerializer(Object.class); |
| | | |
| | | // 使用StringRedisSerializer来序列化和反序列化redis的key值 |
| | | template.setKeySerializer(new StringRedisSerializer()); |
| | | template.setValueSerializer(serializer); |
| | | |
| | | // Hash的key也采用StringRedisSerializer的序列化方式 |
| | | template.setHashKeySerializer(new StringRedisSerializer()); |
| | | template.setHashValueSerializer(serializer); |
| | | |
| | | template.afterPropertiesSet(); |
| | | return template; |
| | | } |
| | | |
| | | @Bean |
| | | public DefaultRedisScript<Long> limitScript() { |