【发布时间】:2021-08-06 20:21:21
【问题描述】:
我正在使用 Spring Boot cassandra 微服务,
我的 docker 文件是,
FROM openjdk:11-jdk-slim
VOLUME /tmp
ARG JAR_FILE=build/libs/*.war
COPY ${JAR_FILE} app.war
EXPOSE 8081
ENTRYPOINT ["java","-jar","/app.war"]
我的 docker compose 是
version: "3"
services:
cassandra_node_1:
image: cassandra:3.11.5
container_name: cassandra_node_1
ports:
- 9042:9042
hostname: cassandra_node_1
mem_limit: 2g
healthcheck:
test: ["CMD", "cqlsh", "-e", "describe keyspaces" ]
interval: 5s
timeout: 5s
retries: 60
environment:
- CASSANDRA_SEEDS=cassandra_node_1
- CASSANDRA_DC=datacenter1
milk-vendor-services:
container_name: milk_vendor_1
build:
context: .
restart: on-failure
ports:
- 8081:8081
environment:
- spring.data.cassandra.contact-points=cassandra_node_1
- spring.data.cassandra.port=9042
- spring.data.cassandra.keyspace-name=milk_vendor
- spring.data.cassandra.local-datacenter=datacenter1
- spring.data.cassandra.schema-action=CREATE_IF_NOT_EXISTS
depends_on:
- cassandra_node_1
当我使用“docker compose up”运行上述内容时。我遇到了错误,在没有 docker 的情况下工作正常。
milk_vendor_1 | 2021-05-16 14:43:24.919 WARN 1 --- [ s0-admin-1] c.d.o.d.i.c.control.ControlConnection : [s0] Error connecting to Node(endPoint=localhost:9042, hostId=null, hashCode=5019c44e), trying next node (ConnectionInitException: [s0|control|connecting...] Protocol initialization request, step 1 (OPTIONS): failed to send request (io.netty.channel.StacklessClosedChannelException))
milk_vendor_1 | 2021-05-16 14:43:24.954 WARN 1 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'milkVendorResource': Unsatisfied dependency expressed through field 'service'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'milkVendorServiceImpl': Unsatisfied dependency expressed through field 'homeRepository'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'IHomeRepository' defined in com.viji.kala.vendor.dao.IHomeRepository defined in @EnableReactiveCassandraRepositories declared on CassandraReactiveRepositoriesRegistrar.EnableReactiveCassandraRepositoriesConfiguration: Cannot resolve reference to bean 'reactiveCassandraTemplate' while setting bean property 'reactiveCassandraOperations'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'reactiveCassandraTemplate' defined in class path resource [com/viji/kala/vendor/config/CassandraConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.cassandra.core.ReactiveCassandraTemplate]: Factory method 'reactiveCassandraTemplate' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'reactiveCassandraSessionFactory' defined in class path resource [com/viji/kala/vendor/config/CassandraConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.cassandra.ReactiveSessionFactory]: Factory method 'reactiveCassandraSessionFactory' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'reactiveCassandraSession' defined in class path resource [com/viji/kala/vendor/config/CassandraConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.cassandra.ReactiveSession]: Factory method 'reactiveCassandraSession' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cassandraSession' defined in class path resource [com/viji/kala/vendor/config/CassandraConfig.class]: Invocation of init method failed; nested exception is com.datastax.oss.driver.api.core.AllNodesFailedException: Could not reach any contact point, make sure you've provided valid addresses (showing first 1 nodes, use getAllErrors() for more): Node(endPoint=localhost:9042, hostId=null, hashCode=5019c44e): [com.datastax.oss.driver.api.core.connection.ConnectionInitException: [s0|control|connecting...] Protocol initialization request, step 1 (OPTIONS): failed to send request (io.netty.channel.StacklessClosedChannelException)]
milk_vendor_1 | 2021-05-16 14:43:24.968 INFO 1 --- [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
milk_vendor_1 | 2021-05-16 14:43:25.174 INFO 1 --- [ main] ConditionEvaluationReportLoggingListener :
milk_vendor_1 |
milk_vendor_1 | Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
milk_vendor_1 | 2021-05-16 14:43:25.520 ERROR 1 --- [ main] o.s.boot.SpringApplication : Application run failed
milk_vendor_1 |
instantiate [org.springframework.data.cassandra.ReactiveSession]: Factory method 'reactiveCassandraSession' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cassandraSession' defined in class path resource [com/viji/kala/vendor/config/CassandraConfig.class]: Invocation of init method failed; nested exception is com.datastax.oss.driver.api.core.AllNodesFailedException: Could not reach any contact point, make sure you've provided valid addresses (showing first 1 nodes, use getAllErrors() for more): Node(endPoint=localhost:9042, hostId=null, hashCode=5019c44e): [com.datastax.oss.driver.api.core.connection.ConnectionInitException: [s0|control|connecting...] Protocol initialization request, step 1 (OPTIONS): failed to send request (io.netty.channel.StacklessClosedChannelException)]
milk_vendor_1 | at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185) ~[spring-beans-5.3.1.jar!/:5.3.1]
milk_vendor_1 | at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:651) ~[spring-beans-5.3.1.jar!/:5.3.1]
milk_vendor_1 | ... 114 common frames omitted
milk_vendor_1 | Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cassandraSession' defined in class path resource [com/viji/kala/vendor/config/CassandraConfig.class]: Invocation of init method failed; nested exception is com.datastax.oss.driver.api.core.AllNodesFailedException: Could not reach any contact point, make sure you've provided valid addresses (showing first 1 nodes, use getAllErrors() for more): Node(endPoint=localhost:9042, hostId=null, hashCode=5019c44e): [com.datastax.oss.driver.api.core.connection.ConnectionInitException: [s0|control|connecting...] Protocol initialization request, step 1 (OPTIONS): failed to send request (io.netty.channel.StacklessClosedChannelException)]
milk_vendor_1 | at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1788) ~[spring-beans-5.3.1.jar!/:5.3.1]
milk_vendor_1 | at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:609) ~[spring-beans-5.3.1.jar!/:5.3.1]
milk_vendor_1 | at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:531) ~[spring-beans-5.3.1.jar!/:5.3.1]
milk_vendor_1 | at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) ~[spring-beans-5.3.1.jar!/:5.3.1]
milk_vendor_1 | at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.3.1.jar!/:5.3.1]
milk_vendor_1 | at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) ~[spring-beans-5.3.1.jar!/:5.3.1]
milk_vendor_1 | at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:233) ~[spring-beans-5.3.1.jar!/:5.3.1]
milk_vendor_1 | at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveNamedBean(DefaultListableBeanFactory.java:1235) ~[spring-beans-5.3.1.jar!/:5.3.1]
milk_vendor_1 | at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveBean(DefaultListableBeanFactory.java:494) ~[spring-beans-5.3.1.jar!/:5.3.1]
milk_vendor_1 | at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:349) ~[spring-beans-5.3.1.jar!/:5.3.1]
milk_vendor_1 | at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:342) ~[spring-beans-5.3.1.jar!/:5.3.1]
milk_vendor_1 | at org.springframework.data.cassandra.config.AbstractSessionConfiguration.requireBeanOfType(AbstractSessionConfiguration.java:100) ~[spring-data-cassandra-3.1.1.jar!/:3.1.1]
milk_vendor_1 | at org.springframework.data.cassandra.config.AbstractSessionConfiguration.getRequiredSession(AbstractSessionConfiguration.java:200) ~[spring-data-cassandra-3.1.1.jar!/:3.1.1]
milk_vendor_1 | at org.springframework.data.cassandra.config.AbstractReactiveCassandraConfiguration.reactiveCassandraSession(AbstractReactiveCassandraConfiguration.java:53) ~[spring-data-cassandra-3.1.1.jar!/:3.1.1]
milk_vendor_1 | at com.viji.kala.vendor.config.CassandraConfig$$EnhancerBySpringCGLIB$$73567517.CGLIB$reactiveCassandraSession$5(<generated>) ~[classes!/:na]
milk_vendor_1 | at com.viji.kala.vendor.config.CassandraConfig$$EnhancerBySpringCGLIB$$73567517$$FastClassBySpringCGLIB$$774c088a.invoke(<generated>) ~[classes!/:na]
milk_vendor_1 | at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:244) ~[spring-core-5.3.1.jar!/:5.3.1]
milk_vendor_1 | at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:331) ~[spring-context-5.3.1.jar!/:5.3.1]
milk_vendor_1 | at com.viji.kala.vendor.config.CassandraConfig$$EnhancerBySpringCGLIB$$73567517.reactiveCassandraSession(<generated>) ~[classes!/:na]
milk_vendor_1 | at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
milk_vendor_1 | at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:na]
milk_vendor_1 | at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
milk_vendor_1 | at java.base/java.lang.reflect.Method.invoke(Method.java:566) ~[na:na]
milk_vendor_1 | at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154) ~[spring-beans-5.3.1.jar!/:5.3.1]
milk_vendor_1 | ... 115 common frames omitted
milk_vendor_1 | Caused by: com.datastax.oss.driver.api.core.AllNodesFailedException: Could not reach any contact point, make sure you've provided valid addresses (showing first 1 nodes, use getAllErrors() for more): Node(endPoint=localhost:9042, hostId=null, hashCode=5019c44e): [com.datastax.oss.driver.api.core.connection.ConnectionInitException: [s0|control|connecting...] Protocol initialization request, step 1 (OPTIONS): failed to send request (io.netty.channel.StacklessClosedChannelException)]
milk_vendor_1 | at com.datastax.oss.driver.api.core.AllNodesFailedException.copy(AllNodesFailedException.java:141) ~[java-driver-core-4.9.0.jar!/:na]
milk_vendor_1 | at com.datastax.oss.driver.internal.core.util.concurrent.CompletableFutures.getUninterruptibly(CompletableFutures.java:149) ~[java-driver-core-4.9.0.jar!/:na]
milk_vendor_1 | at com.datastax.oss.driver.api.core.session.SessionBuilder.build(SessionBuilder.java:697) ~[java-driver-core-4.9.0.jar!/:na]
milk_vendor_1 | at org.springframework.data.cassandra.config.CqlSessionFactoryBean.buildSystemSession(CqlSessionFactoryBean.java:498) ~[spring-data-cassandra-3.1.1.jar!/:3.1.1]
milk_vendor_1 | at org.springframework.data.cassandra.config.CqlSessionFactoryBean.afterPropertiesSet(CqlSessionFactoryBean.java:451) ~[spring-data-cassandra-3.1.1.jar!/:3.1.1]
milk_vendor_1 | at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1847) ~[spring-beans-5.3.1.jar!/:5.3.1]
milk_vendor_1 | at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1784) ~[spring-beans-5.3.1.jar!/:5.3.1]
milk_vendor_1 | ... 138 common frames omitted
milk_vendor_1 | Suppressed: com.datastax.oss.driver.api.core.connection.ConnectionInitException: [s0|control|connecting...] Protocol initialization request, step 1 (OPTIONS): failed to send request (io.netty.channel.StacklessClosedChannelException)
milk_vendor_1 | at com.datastax.oss.driver.internal.core.channel.ProtocolInitHandler$InitRequest.fail(ProtocolInitHandler.java:354) ~[java-driver-core-4.9.0.jar!/:na]
milk_vendor_1 | at com.datastax.oss.driver.internal.core.channel.ChannelHandlerRequest.writeListener(ChannelHandlerRequest.java:87) ~[java-driver-core-4.9.0.jar!/:na]
milk_vendor_1 | at io.netty.util.concurrent.DefaultPromise.notifyListener0(DefaultPromise.java:578) ~[netty-common-4.1.54.Final.jar!/:4.1.54.Final]
milk_vendor_1 | at io.netty.util.concurrent.DefaultPromise.notifyListenersNow(DefaultPromise.java:552) ~[netty-common-4.1.54.Final.jar!/:4.1.54.Final]
milk_vendor_1 | at io.netty.util.concurrent.DefaultPromise.notifyListeners(DefaultPromise.java:491) ~[netty-common-4.1.54.Final.jar!/:4.1.54.Final]
milk_vendor_1 | at io.netty.util.concurrent.DefaultPromise.addListener(DefaultPromise.java:184) ~[netty-common-4.1.54.Final.jar!/:4.1.54.Final]
milk_vendor_1 | at io.netty.channel.DefaultChannelPromise.addListener(DefaultChannelPromise.java:95) ~[netty-transport-4.1.54.Final.jar!/:4.1.54.Final]
milk_vendor_1 | at io.netty.channel.DefaultChannelPromise.addListener(DefaultChannelPromise.java:30) ~[netty-transport-4.1.54.Final.jar!/:4.1.54.Final]
milk_vendor_1 | at com.datastax.oss.driver.internal.core.channel.ChannelHandlerRequest.send(ChannelHandlerRequest.java:76) ~[java-driver-core-4.9.0.jar!/:na]
milk_vendor_1 | at com.datastax.oss.driver.internal.core.channel.ProtocolInitHandler$InitRequest.send(ProtocolInitHandler.java:193) ~[java-driver-core-4.9.0.jar!/:na]
milk_vendor_1 | at com.datastax.oss.driver.internal.core.channel.ProtocolInitHandler.onRealConnect(ProtocolInitHandler.java:124) ~[java-driver-core-4.9.0.jar!/:na]
milk_vendor_1 | at com.datastax.oss.driver.internal.core.channel.ConnectInitHandler.lambda$connect$0(ConnectInitHandler.java:57) ~[java-driver-core-4.9.0.jar!/:na]
milk_vendor_1 | at io.netty.util.concurrent.DefaultPromise.notifyListener0(DefaultPromise.java:578) ~[netty-common-4.1.54.Final.jar!/:4.1.54.Final]
milk_vendor_1 | at io.netty.util.concurrent.DefaultPromise.notifyListeners0(DefaultPromise.java:571) ~[netty-common-4.1.54.Final.jar!/:4.1.54.Final]
milk_vendor_1 | at io.netty.util.concurrent.DefaultPromise.notifyListenersNow(DefaultPromise.java:550) ~[netty-common-4.1.54.Final.jar!/:4.1.54.Final]
milk_vendor_1 | at io.netty.util.concurrent.DefaultPromise.notifyListeners(DefaultPromise.java:491) ~[netty-common-4.1.54.Final.jar!/:4.1.54.Final]
milk_vendor_1 | at io.netty.util.concurrent.DefaultPromise.setValue0(DefaultPromise.java:616) ~[netty-common-4.1.54.Final.jar!/:4.1.54.Final]
milk_vendor_1 | at io.netty.util.concurrent.DefaultPromise.setFailure0(DefaultPromise.java:609) ~[netty-common-4.1.54.Final.jar!/:4.1.54.Final]
milk_vendor_1 | at io.netty.util.concurrent.DefaultPromise.tryFailure(DefaultPromise.java:117) ~[netty-common-4.1.54.Final.jar!/:4.1.54.Final]
milk_vendor_1 | at io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe.fulfillConnectPromise(AbstractNioChannel.java:321) ~[netty-transport-4.1.54.Final.jar!/:4.1.54.Final]
milk_vendor_1 | at io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe.finishConnect(AbstractNioChannel.java:337) ~[netty-transport-4.1.54.Final.jar!/:4.1.54.Final]
milk_vendor_1 | at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:707) ~[netty-transport-4.1.54.Final.jar!/:4.1.54.Final]
milk_vendor_1 | at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:655) ~[netty-transport-4.1.54.Final.jar!/:4.1.54.Final]
milk_vendor_1 | at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:581) ~[netty-transport-4.1.54.Final.jar!/:4.1.54.Final]
milk_vendor_1 | at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:493) ~[netty-transport-4.1.54.Final.jar!/:4.1.54.Final]
milk_vendor_1 | at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:989) ~[netty-common-4.1.54.Final.jar!/:4.1.54.Final]
milk_vendor_1 | at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74) ~[netty-common-4.1.54.Final.jar!/:4.1.54.Final]
milk_vendor_1 | at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) ~[netty-common-4.1.54.Final.jar!/:4.1.54.Final]
milk_vendor_1 | at java.base/java.lang.Thread.run(Thread.java:829) ~[na:na]
milk_vendor_1 | Suppressed: io.netty.channel.AbstractChannel$AnnotatedConnectException: Connection refused: localhost/127.0.0.1:9042
milk_vendor_1 | Caused by: java.net.ConnectException: Connection refused
milk_vendor_1 | at java.base/sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
milk_vendor_1 | at java.base/sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:777)
milk_vendor_1 | at io.netty.channel.socket.nio.NioSocketChannel.doFinishConnect(NioSocketChannel.java:330)
milk_vendor_1 | at io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe.finishConnect(AbstractNioChannel.java:334)
milk_vendor_1 | at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:707)
milk_vendor_1 | at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:655)
milk_vendor_1 | at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:581)
milk_vendor_1 | at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:493)
milk_vendor_1 | at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:989)
milk_vendor_1 | at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
milk_vendor_1 | at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
milk_vendor_1 | at java.base/java.lang.Thread.run(Thread.java:829)
milk_vendor_1 | Caused by: io.netty.channel.StacklessClosedChannelException: null
milk_vendor_1 | at io.netty.channel.AbstractChannel$AbstractUnsafe.flush0()(Unknown Source)
【问题讨论】:
标签: spring spring-boot docker cassandra microservices