Commit 3ea8a693 by tangyi

修复Redis配置失效bug

parent 29540ce8
...@@ -94,16 +94,6 @@ ...@@ -94,16 +94,6 @@
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId> <artifactId>spring-boot-starter-data-redis</artifactId>
<exclusions>
<exclusion>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
</dependency> </dependency>
<!-- 配置属性加密工具 --> <!-- 配置属性加密工具 -->
<dependency> <dependency>
......
...@@ -3,7 +3,7 @@ package com.github.tangyi.common.core.config; ...@@ -3,7 +3,7 @@ package com.github.tangyi.common.core.config;
import org.springframework.cache.annotation.EnableCaching; import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory; import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.*; import org.springframework.data.redis.core.*;
import org.springframework.data.redis.serializer.JdkSerializationRedisSerializer; import org.springframework.data.redis.serializer.JdkSerializationRedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer; import org.springframework.data.redis.serializer.StringRedisSerializer;
...@@ -19,18 +19,16 @@ import org.springframework.data.redis.serializer.StringRedisSerializer; ...@@ -19,18 +19,16 @@ import org.springframework.data.redis.serializer.StringRedisSerializer;
public class RedisConfig { public class RedisConfig {
@Bean @Bean
public JedisConnectionFactory jedisConnectionFactory() { public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory redisConnectionFactory) {
return new JedisConnectionFactory();
}
@Bean
public RedisTemplate<String, Object> redisTemplate() {
RedisTemplate<String, Object> redisTemplate = new RedisTemplate<>(); RedisTemplate<String, Object> redisTemplate = new RedisTemplate<>();
// 存储对象需要配置序列化机制
redisTemplate.setKeySerializer(new StringRedisSerializer()); redisTemplate.setKeySerializer(new StringRedisSerializer());
redisTemplate.setHashKeySerializer(new StringRedisSerializer()); redisTemplate.setHashKeySerializer(new StringRedisSerializer());
redisTemplate.setValueSerializer(new JdkSerializationRedisSerializer()); redisTemplate.setValueSerializer(new JdkSerializationRedisSerializer());
redisTemplate.setHashValueSerializer(new JdkSerializationRedisSerializer()); redisTemplate.setHashValueSerializer(new JdkSerializationRedisSerializer());
redisTemplate.setConnectionFactory(jedisConnectionFactory()); // 开启事务
redisTemplate.setEnableTransactionSupport(true);
redisTemplate.setConnectionFactory(redisConnectionFactory);
return redisTemplate; return redisTemplate;
} }
......
...@@ -8,7 +8,7 @@ spring: ...@@ -8,7 +8,7 @@ spring:
type: com.alibaba.druid.pool.DruidDataSource type: com.alibaba.druid.pool.DruidDataSource
driver-class-name: com.mysql.jdbc.Driver driver-class-name: com.mysql.jdbc.Driver
redis: redis:
host: ${REDIS_HOST:localhost} host: ${REDIS_HOST:192.168.0.213}
port: ${REDIS_PORT:6379} port: ${REDIS_PORT:6379}
rabbitmq: rabbitmq:
host: ${RABBIT_HOST:localhost} host: ${RABBIT_HOST:localhost}
......
...@@ -8,7 +8,7 @@ spring: ...@@ -8,7 +8,7 @@ spring:
type: com.alibaba.druid.pool.DruidDataSource type: com.alibaba.druid.pool.DruidDataSource
driver-class-name: com.mysql.jdbc.Driver driver-class-name: com.mysql.jdbc.Driver
redis: redis:
host: ${REDIS_HOST:localhost} host: ${REDIS_HOST:192.168.0.213}
port: ${REDIS_PORT:6379} port: ${REDIS_PORT:6379}
rabbitmq: rabbitmq:
host: ${RABBIT_HOST:localhost} host: ${RABBIT_HOST:localhost}
......
...@@ -2,7 +2,7 @@ server: ...@@ -2,7 +2,7 @@ server:
port: 8000 port: 8000
spring: spring:
redis: redis:
host: ${REDIS_HOST:localhost} host: ${REDIS_HOST:192.168.0.213}
port: ${REDIS_PORT:6379} port: ${REDIS_PORT:6379}
boot: boot:
admin: admin:
......
...@@ -8,7 +8,7 @@ spring: ...@@ -8,7 +8,7 @@ spring:
type: com.alibaba.druid.pool.DruidDataSource type: com.alibaba.druid.pool.DruidDataSource
driver-class-name: com.mysql.jdbc.Driver driver-class-name: com.mysql.jdbc.Driver
redis: redis:
host: ${REDIS_HOST:localhost} host: ${REDIS_HOST:192.168.0.213}
port: ${REDIS_PORT:6379} port: ${REDIS_PORT:6379}
rabbitmq: rabbitmq:
host: ${RABBIT_HOST:localhost} host: ${RABBIT_HOST:localhost}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment