redis操作数据(2) applicationContext-redis.xml

本文详细介绍了如何在Spring Boot项目中配置Redis连接池,包括最大空闲连接数、最大等待时间、借出连接前的测试等参数设置,以及如何通过JedisConnectionFactory建立连接。
<?xml version="1.0" encoding="UTF-8"?>

<context:property-placeholder location="classpath*:*.properties" />
<!-- redis 相关配置 -->
<bean id="poolConfig" class="redis.clients.jedis.JedisPoolConfig">
    <property name="maxIdle" value="${redis.maxIdle}" />
    <property name="maxWaitMillis" value="${redis.maxWait}" />
    <property name="testOnBorrow" value="${redis.testOnBorrow}" />
</bean>
<bean id="JedisConnectionFactory" class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory"
      p:host-name="${redis.host}" p:port="${redis.port}" p:password="${redis.pass}" p:pool-config-ref="poolConfig"/>

<bean id="redisTemplate" class="org.springframework.data.redis.core.RedisTemplate">
    <property name="connectionFactory" ref="JedisConnectionFactory" />
</bean>
2025-10-04T22:42:23.873+08:00 WARN 13556 --- [BoWenTongJianTest] [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'commonConfig': Unsatisfied dependency expressed through field 'redisEmbeddingStore': Error creating bean with name 'redisEmbeddingStore' defined in class path resource [dev/langchain4j/community/store/embedding/redis/spring/RedisEmbeddingStoreAutoConfiguration.class]: Failed to instantiate [dev.langchain4j.community.store.embedding.redis.RedisEmbeddingStore]: Factory method 'redisEmbeddingStore' threw exception with message: Failed to connect to localhost:6379. 2025-10-04T22:42:23.889+08:00 INFO 13556 --- [BoWenTongJianTest] [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat] 2025-10-04T22:42:23.900+08:00 INFO 13556 --- [BoWenTongJianTest] [ main] .s.b.a.l.ConditionEvaluationReportLogger : Error starting ApplicationContext. To display the condition evaluation report re-run your application with 'debug' enabled. 2025-10-04T22:42:23.919+08:00 ERROR 13556 --- [BoWenTongJianTest] [ main] o.s.boot.SpringApplication : Application run failed org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'commonConfig': Unsatisfied dependency expressed through field 'redisEmbeddingStore': Error creating bean with name 'redisEmbeddingStore' defined in class path resource [dev/langchain4j/community/store/embedding/redis/spring/RedisEmbeddingStoreAutoConfiguration.class]: Failed to instantiate [dev.langchain4j.community.store.embedding.redis.RedisEmbeddingStore]: Factory method 'redisEmbeddingStore' threw exception with message: Failed to connect to localhost:6379. at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.resolveFieldValue(AutowiredAnnotationBeanPostProcessor.java:788) ~[spring-beans-6.2.11.jar:6.2.11] at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:768) ~[spring-beans-6.2.11.jar:6.2.11] at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:146) ~[spring-beans-6.2.11.jar:6.2.11] at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessProperties(AutowiredAnnotationBeanPostProcessor.java:509) ~[spring-beans-6.2.11.jar:6.2.11] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1459) ~[spring-beans-6.2.11.jar:6.2.11] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:606) ~[spring-beans-6.2.11.jar:6.2.11] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:529) ~[spring-beans-6.2.11.jar:6.2.11] at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:339) ~[spring-beans-6.2.11.jar:6.2.11] at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:373) ~[spring-beans-6.2.11.jar:6.2.11] at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:337) ~[spring-beans-6.2.11.jar:6.2.11] at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) ~[spring-beans-6.2.11.jar:6.2.11] at org.springframework.beans.factory.support.DefaultListableBeanFactory.instantiateSingleton(DefaultListableBeanFactory.java:1221) ~[spring-beans-6.2.11.jar:6.2.11] at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingleton(DefaultListableBeanFactory.java:1187) ~[spring-beans-6.2.11.jar:6.2.11] at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:1123) ~[spring-beans-6.2.11.jar:6.2.11] at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:987) ~[spring-context-6.2.11.jar:6.2.11] at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:627) ~[spring-context-6.2.11.jar:6.2.11] at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:146) ~[spring-boot-3.5.6.jar:3.5.6] at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:752) ~[spring-boot-3.5.6.jar:3.5.6] at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:439) ~[spring-boot-3.5.6.jar:3.5.6] at org.springframework.boot.SpringApplication.run(SpringApplication.java:318) ~[spring-boot-3.5.6.jar:3.5.6] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1361) ~[spring-boot-3.5.6.jar:3.5.6] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1350) ~[spring-boot-3.5.6.jar:3.5.6] at com.zhaorunsen.bowentongjiantest.BoWenTongJianTestApplication.main(BoWenTongJianTestApplication.java:12) ~[classes/:na] Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'redisEmbeddingStore' defined in class path resource [dev/langchain4j/community/store/embedding/redis/spring/RedisEmbeddingStoreAutoConfiguration.class]: Failed to instantiate [dev.langchain4j.community.store.embedding.redis.RedisEmbeddingStore]: Factory method 'redisEmbeddingStore' threw exception with message: Failed to connect to localhost:6379. at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:657) ~[spring-beans-6.2.11.jar:6.2.11] at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:645) ~[spring-beans-6.2.11.jar:6.2.11] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1375) ~[spring-beans-6.2.11.jar:6.2.11] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1205) ~[spring-beans-6.2.11.jar:6.2.11] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:569) ~[spring-beans-6.2.11.jar:6.2.11] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:529) ~[spring-beans-6.2.11.jar:6.2.11] at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:339) ~[spring-beans-6.2.11.jar:6.2.11] at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:373) ~[spring-beans-6.2.11.jar:6.2.11] at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:337) ~[spring-beans-6.2.11.jar:6.2.11] at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) ~[spring-beans-6.2.11.jar:6.2.11] at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1698) ~[spring-beans-6.2.11.jar:6.2.11] at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1643) ~[spring-beans-6.2.11.jar:6.2.11] at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.resolveFieldValue(AutowiredAnnotationBeanPostProcessor.java:785) ~[spring-beans-6.2.11.jar:6.2.11] ... 22 common frames omitted Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [dev.langchain4j.community.store.embedding.redis.RedisEmbeddingStore]: Factory method 'redisEmbeddingStore' threw exception with message: Failed to connect to localhost:6379. at org.springframework.beans.factory.support.SimpleInstantiationStrategy.lambda$instantiate$0(SimpleInstantiationStrategy.java:200) ~[spring-beans-6.2.11.jar:6.2.11] at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiateWithFactoryMethod(SimpleInstantiationStrategy.java:89) ~[spring-beans-6.2.11.jar:6.2.11] at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:169) ~[spring-beans-6.2.11.jar:6.2.11] at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:653) ~[spring-beans-6.2.11.jar:6.2.11] ... 34 common frames omitted Caused by: redis.clients.jedis.exceptions.JedisConnectionException: Failed to connect to localhost:6379. at redis.clients.jedis.DefaultJedisSocketFactory.connectToFirstSuccessfulHost(DefaultJedisSocketFactory.java:68) ~[jedis-6.0.0.jar:na] at redis.clients.jedis.DefaultJedisSocketFactory.createSocket(DefaultJedisSocketFactory.java:94) ~[jedis-6.0.0.jar:na] at redis.clients.jedis.Connection.connect(Connection.java:232) ~[jedis-6.0.0.jar:na] at redis.clients.jedis.Connection.initializeFromClientConfig(Connection.java:455) ~[jedis-6.0.0.jar:na] at redis.clients.jedis.Connection.<init>(Connection.java:77) ~[jedis-6.0.0.jar:na] at redis.clients.jedis.ConnectionFactory.lambda$connectionSupplier$1(ConnectionFactory.java:72) ~[jedis-6.0.0.jar:na] at redis.clients.jedis.ConnectionFactory.makeObject(ConnectionFactory.java:96) ~[jedis-6.0.0.jar:na] at org.apache.commons.pool2.impl.GenericObjectPool.create(GenericObjectPool.java:557) ~[commons-pool2-2.12.1.jar:2.12.1] at org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:299) ~[commons-pool2-2.12.1.jar:2.12.1] at org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:231) ~[commons-pool2-2.12.1.jar:2.12.1] at redis.clients.jedis.util.Pool.getResource(Pool.java:38) ~[jedis-6.0.0.jar:na] at redis.clients.jedis.ConnectionPool.getResource(ConnectionPool.java:52) ~[jedis-6.0.0.jar:na] at redis.clients.jedis.ConnectionPool.getResource(ConnectionPool.java:12) ~[jedis-6.0.0.jar:na] at redis.clients.jedis.providers.PooledConnectionProvider.getConnection(PooledConnectionProvider.java:83) ~[jedis-6.0.0.jar:na] at redis.clients.jedis.executors.DefaultCommandExecutor.executeCommand(DefaultCommandExecutor.java:23) ~[jedis-6.0.0.jar:na] at redis.clients.jedis.UnifiedJedis.executeCommand(UnifiedJedis.java:311) ~[jedis-6.0.0.jar:na] at redis.clients.jedis.UnifiedJedis.ftList(UnifiedJedis.java:4174) ~[jedis-6.0.0.jar:na] at dev.langchain4j.community.store.embedding.redis.RedisEmbeddingStore.isIndexExist(RedisEmbeddingStore.java:244) ~[langchain4j-community-redis-1.0.1-beta6.jar:na] at dev.langchain4j.community.store.embedding.redis.RedisEmbeddingStore.<init>(RedisEmbeddingStore.java:108) ~[langchain4j-community-redis-1.0.1-beta6.jar:na] at dev.langchain4j.community.store.embedding.redis.RedisEmbeddingStore$Builder.build(RedisEmbeddingStore.java:452) ~[langchain4j-community-redis-1.0.1-beta6.jar:na] at dev.langchain4j.community.store.embedding.redis.spring.RedisEmbeddingStoreAutoConfiguration.redisEmbeddingStore(RedisEmbeddingStoreAutoConfiguration.java:35) ~[langchain4j-community-redis-spring-boot-starter-1.0.1-beta6.jar:na] at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103) ~[na:na] at java.base/java.lang.reflect.Method.invoke(Method.java:580) ~[na:na] at org.springframework.beans.factory.support.SimpleInstantiationStrategy.lambda$instantiate$0(SimpleInstantiationStrategy.java:172) ~[spring-beans-6.2.11.jar:6.2.11] ... 37 common frames omitted Suppressed: java.net.ConnectException: Connection refused: getsockopt at java.base/sun.nio.ch.Net.pollConnect(Native Method) ~[na:na] at java.base/sun.nio.ch.Net.pollConnectNow(Net.java:682) ~[na:na] at java.base/sun.nio.ch.NioSocketImpl.timedFinishConnect(NioSocketImpl.java:542) ~[na:na] at java.base/sun.nio.ch.NioSocketImpl.connect(NioSocketImpl.java:592) ~[na:na] at java.base/java.net.SocksSocketImpl.connect(SocksSocketImpl.java:327) ~[na:na] at java.base/java.net.Socket.connect(Socket.java:751) ~[na:na] at redis.clients.jedis.DefaultJedisSocketFactory.connectToFirstSuccessfulHost(DefaultJedisSocketFactory.java:80) ~[jedis-6.0.0.jar:na] ... 60 common frames omitted Suppressed: java.net.ConnectException: Connection refused: getsockopt at java.base/sun.nio.ch.Net.pollConnect(Native Method) ~[na:na] at java.base/sun.nio.ch.Net.pollConnectNow(Net.java:682) ~[na:na] at java.base/sun.nio.ch.NioSocketImpl.timedFinishConnect(NioSocketImpl.java:542) ~[na:na] at java.base/sun.nio.ch.NioSocketImpl.connect(NioSocketImpl.java:592) ~[na:na] at java.base/java.net.SocksSocketImpl.connect(SocksSocketImpl.java:327) ~[na:na] at java.base/java.net.Socket.connect(Socket.java:751) ~[na:na] at redis.clients.jedis.DefaultJedisSocketFactory.connectToFirstSuccessfulHost(DefaultJedisSocketFactory.java:80) ~[jedis-6.0.0.jar:na] ... 60 common frames omitted Process finished with exit code 1 中文回答
最新发布
10-05
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值