SpringBoot数据Redis配置不起作用或有一些奇怪的行为

时间:2020-07-01 20:13:29

标签: spring-boot google-cloud-platform redis

我有一个简单的springboot应用程序,它将使用redis缓存功能。我的本地机器上已经有一个Redis服务器,并且我的应用程序还使用了spring-boot-data-redis依赖项。奇怪的是,当我在本地计算机上运行我的应用程序同时还运行Redis服务器时,我可以轻松地将缓存键值推送到Redis服务器。要查看Redis服务器中的键-我使用命令KEYS *,但是当我在GCP中部署应用程序时,它不会将任何缓存键值推送到GCP Redis服务器。我检查了我的应用程序的Google Stack驱动程序(日志),但未遇到任何错误。实际上,我感到震惊是因为我的应用程序启动时没有错误,因为我认为它没有成功连接到GCP redis服务器。我试图关闭本地计算机上的Redis服务器,并且本地应用程序显示一些错误。有人可以帮忙吗?我在这个错误中停留了1周。

build.gradle

compile "org.springframework.boot:spring-boot-starter-data-redis"

配置类

@Configuration
public class RedisCacheConfig {

    @Bean   
    public RedisCacheManager cacheManager(final RedisConnectionFactory connectionFactory) {
        final RedisCacheWriter redisCacheWriter = RedisCacheWriter.lockingRedisCacheWriter(connectionFactory);
        final RedisCacheConfiguration cacheConfiguration = RedisCacheConfiguration.defaultCacheConfig().disableCachingNullValues();
        return new RedisCacheManager(redisCacheWriter, cacheConfiguration);
    }
}

application.properties

spring.redis.host=<ip or hostname>
spring.redis.port=6379
spring.redis.password=
spring.cache.type=redis
spring.redis.timeout=30000

我的主要班级

@SpringBootApplication
@EnableCaching
public class Application extends SpringBootServletInitializer {

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}

0 个答案:

没有答案
相关问题