Closed helpudie closed 2 months ago
当yml为如下:
当redis不可用时, 启动项目就会报错:
15:59:17.471 [main] INFO c.a.j.a.AbstractCacheAutoInit - [process,74] - init cache area default , type= caffeine 15:59:17.513 [main] INFO c.a.j.a.AbstractCacheAutoInit - [process,74] - init cache area default , type= redis.lettuce 15:59:28.199 [lettuce-nioEventLoop-4-1] WARN i.l.c.m.StaticMasterReplicaTopologyProvider - [lambda$getNodeDescription$2,102] - Cannot connect to redis://192.168.222.12 io.lettuce.core.RedisConnectionException: Unable to connect to 192.168.222.12:6379 at io.lettuce.core.RedisConnectionException.create(RedisConnectionException.java:78) at io.lettuce.core.RedisConnectionException.create(RedisConnectionException.java:56) at io.lettuce.core.RedisClient.lambda$transformAsyncConnectionException$22(RedisClient.java:781) at io.lettuce.core.DefaultConnectionFuture.lambda$thenCompose$1(DefaultConnectionFuture.java:253) at java.util.concurrent.CompletableFuture.uniWhenComplete(CompletableFuture.java:774) at java.util.concurrent.CompletableFuture$UniWhenComplete.tryFire(CompletableFuture.java:750) at java.util.concurrent.CompletableFuture.postComplete(CompletableFuture.java:488) at java.util.concurrent.CompletableFuture.completeExceptionally(CompletableFuture.java:1990) at io.lettuce.core.AbstractRedisClient.lambda$initializeChannelAsync0$6(AbstractRedisClient.java:424) at io.netty.util.concurrent.DefaultPromise.notifyListener0(DefaultPromise.java:590) at io.netty.util.concurrent.DefaultPromise.notifyListeners0(DefaultPromise.java:583) at io.netty.util.concurrent.DefaultPromise.notifyListenersNow(DefaultPromise.java:559) at io.netty.util.concurrent.DefaultPromise.notifyListeners(DefaultPromise.java:492) at io.netty.util.concurrent.DefaultPromise.setValue0(DefaultPromise.java:636) at io.netty.util.concurrent.DefaultPromise.setFailure0(DefaultPromise.java:629) at io.netty.util.concurrent.DefaultPromise.tryFailure(DefaultPromise.java:118) at io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe$1.run(AbstractNioChannel.java:262) at io.netty.util.concurrent.PromiseTask.runTask(PromiseTask.java:98) at io.netty.util.concurrent.ScheduledFutureTask.run(ScheduledFutureTask.java:153) at io.netty.util.concurrent.AbstractEventExecutor.runTask$$$capture(AbstractEventExecutor.java:174) at io.netty.util.concurrent.AbstractEventExecutor.runTask(AbstractEventExecutor.java) at io.netty.util.concurrent.AbstractEventExecutor.safeExecute$$$capture(AbstractEventExecutor.java:167) at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java) at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:470) at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:569) at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:997) at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74) at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) at java.lang.Thread.run(Thread.java:750) Caused by: java.util.concurrent.CompletionException: io.netty.channel.ConnectTimeoutException: connection timed out: /192.168.222.12:6379 at java.util.concurrent.CompletableFuture.encodeThrowable(CompletableFuture.java:292) at java.util.concurrent.CompletableFuture.completeThrowable(CompletableFuture.java:308) at java.util.concurrent.CompletableFuture.uniApply(CompletableFuture.java:607) at java.util.concurrent.CompletableFuture$UniApply.tryFire(CompletableFuture.java:591) ... 23 common frames omitted Caused by: io.netty.channel.ConnectTimeoutException: connection timed out: /192.168.222.12:6379 at io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe$1.run(AbstractNioChannel.java:261) ... 12 common frames omitted 15:59:28.205 [main] ERROR o.s.b.w.e.t.TomcatStarter - [onStartup,61] - Error starting Tomcat context. Exception: org.springframework.beans.factory.UnsatisfiedDependencyException. Message: Error creating bean with name 'jwtAuthenticationTokenFilter': Unsatisfied dependency expressed through field 'tokenService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'tokenService': Unsatisfied dependency expressed through field 'doubleCache'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'doubleCache': Unsatisfied dependency expressed through field 'doubleCache'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'jetCacheConfig': Unsatisfied dependency expressed through field 'cacheManager'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'jcCacheManager' defined in class path resource [com/alicp/jetcache/autoconfigure/JetCacheAutoConfiguration.class]: Unsatisfied dependency expressed through method 'cacheManager' parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'springConfigProvider' defined in class path resource [com/alicp/jetcache/autoconfigure/JetCacheAutoConfiguration.class]: Unsatisfied dependency expressed through method 'springConfigProvider' parameter 1; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'redisLettuceAutoInit' defined in class path resource [com/alicp/jetcache/autoconfigure/RedisLettuceAutoConfiguration.class]: Invocation of init method failed; nested exception is io.lettuce.core.RedisConnectionException: Unable to connect to [redis://192.168.222.12] 15:59:28.240 [main] INFO o.a.c.c.StandardService - [log,173] - Stopping service [Tomcat] 15:59:28.418 [main] WARN o.a.c.l.WebappClassLoaderBase - [log,173] - The web application [ROOT] appears to have started a thread named [lettuce-timer-3-1] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread: java.lang.Thread.sleep(Native Method) io.netty.util.HashedWheelTimer$Worker.waitForNextTick(HashedWheelTimer.java:600) io.netty.util.HashedWheelTimer$Worker.run(HashedWheelTimer.java:496) io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) java.lang.Thread.run(Thread.java:750) ......
但是redis可用时,可正常启动,并且此时redis再变为不可用,系统会使用本地缓存,redis恢复可用后,变为正常二级缓存。 请问是否有配置可以做到,redis不可用时,也能正常启动,只是使用本地缓存。
如果是生产环境,连不上redis就该堵塞启动。
如果是测试环境没有redis,你把远程的换成mock也行。
谢谢解答,还有个问题是能否自定义redis的序列化方式(例如StringRedisSerializer),我看目前有java/kryo/kryo5
可以的,你看看代码就知道了
好的 感谢,已解决问题
2.7.6版本