- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
编辑:解决方案如Valijon所述。但是此外,在我第一次插入DemoApplication.java之前,缺少以下行:
MongoOperations mongoOps = new MongoTemplate(new SimpleMongoClientDbFactory(new ConnectionString("mongodb://docker_mongo:27017/db")));
docker-compose up
创建了一个容器“docker_mongo”和一个名为“docker_spring”的容器。
application.properties
(请参见下文)。
spring.data.mongodb.host=mongo
spring.data.mongodb.port=27017
spring.data.mongodb.database=db
spring.data.mongodb.uri=mongodb://docker_mongo:27017/db
FROM openjdk:11
VOLUME /tmp
ARG JAR_FILE=target/*.jar
COPY ${JAR_FILE} /tmp/app.jar
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/tmp/app.jar"]
RUN echo "hello world"
version: '3.1'
services:
mongo:
container_name: docker_mongo
networks:
- gateway
ports:
- "27017:27017"
hostname: mongo
image: mongo:latest
command: mongod --port 27017
volumes:
- ./data/db:/data/db
spring:
build: .
container_name: docker_spring
networks:
- gateway
ports:
- "8080:8080"
hostname: spring
depends_on:
- mongo
networks:
gateway:
driver: "bridge"
package com.example.demo;
import com.example.model.Expenditure;
import com.mongodb.client.MongoClients;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.data.mongodb.core.MongoOperations;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.SimpleMongoClientDbFactory;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import java.time.LocalDate;
/*
@SpringBootApplication(exclude={
MongoAutoConfiguration.class,
MongoDataAutoConfiguration.class
})
*/
@SpringBootApplication
@ComponentScan({"com.example.client","com.example.demo","com.example.model"})
public class DemoApplication implements CommandLineRunner {
@Autowired
private ExpenditureRepository repository;
@Override
public void run(String... args) throws Exception {
MongoOperations mongoOps = new MongoTemplate(new SimpleMongoClientDbFactory(MongoClients.create(), "db"));
mongoOps.insert(new Expenditure("Aldi",10.01, LocalDate.parse("2019-10-05")));
System.out.println(mongoOps.findOne(new Query(Criteria.where("name").is("Aldi")),Expenditure.class));
mongoOps.dropCollection("expenditure");
PopulateExpenditureDB.populateExpenditures(mongoOps);
}
}
package com.example.demo;
import com.mongodb.client.MongoDatabase;
import org.springframework.dao.DataAccessException;
public interface MongoDbFactory {
MongoDatabase getDb() throws DataAccessException;
MongoDatabase getDb(String dbName) throws DataAccessException;
}
package com.example.demo;
import com.example.model.Expenditure;
import java.time.LocalDate;
import java.util.List;
import org.springframework.data.mongodb.repository.MongoRepository;
//mongodb Host & Port defined in application.properties
public interface ExpenditureRepository extends MongoRepository<Expenditure, String> {
/*
public void create(Expenditure expenditure) {
if(expenditure.)
}
public Expenditure findById(int id) {
return data.get(id)
}
*/
public Expenditure findByName (String name);
public List<Expenditure> findByExDate (LocalDate exDate);
}
~/new_Webapp$ sudo docker-compose up
Creating network "newwebapp_gateway" with driver "bridge"
Building spring
Step 1/6 : FROM openjdk:11
---> 612d4d483eee
Step 2/6 : VOLUME /tmp
---> Running in 3aff2f893162
Removing intermediate container 3aff2f893162
---> 2bf19d4c67b1
Step 3/6 : ARG JAR_FILE=target/*.jar
---> Running in b7c3782bbc1a
Removing intermediate container b7c3782bbc1a
---> b029607db12b
Step 4/6 : COPY ${JAR_FILE} /tmp/app.jar
---> f3168bc17ae3
Step 5/6 : ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/tmp/app.jar"]
---> Running in f729f7204cdd
Removing intermediate container f729f7204cdd
---> aceb4c1a0bda
Step 6/6 : RUN echo "hello world"
---> Running in d4ab9bb0f498
hello world
Removing intermediate container d4ab9bb0f498
---> 45ae63ef2bd1
Successfully built 45ae63ef2bd1
Successfully tagged newwebapp_spring:latest
WARNING: Image for service spring was built because it did not already exist. To rebuild this image you must use `docker-compose build` or `docker-compose up --build`.
Creating docker_mongo ...
Creating docker_mongo ... done
Creating docker_spring ...
Creating docker_spring ... done
Attaching to docker_mongo, docker_spring
docker_mongo | 2020-02-07T14:45:26.462+0000 I CONTROL [main] Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'
docker_mongo | 2020-02-07T14:45:26.464+0000 I CONTROL [initandlisten] MongoDB starting : pid=1 port=27017 dbpath=/data/db 64-bit host=mongo
docker_mongo | 2020-02-07T14:45:26.464+0000 I CONTROL [initandlisten] db version v4.2.2
docker_mongo | 2020-02-07T14:45:26.464+0000 I CONTROL [initandlisten] git version: a0bbbff6ada159e19298d37946ac8dc4b497eadf
docker_mongo | 2020-02-07T14:45:26.464+0000 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.1.1 11 Sep 2018
docker_mongo | 2020-02-07T14:45:26.464+0000 I CONTROL [initandlisten] allocator: tcmalloc
docker_mongo | 2020-02-07T14:45:26.464+0000 I CONTROL [initandlisten] modules: none
docker_mongo | 2020-02-07T14:45:26.464+0000 I CONTROL [initandlisten] build environment:
docker_mongo | 2020-02-07T14:45:26.464+0000 I CONTROL [initandlisten] distmod: ubuntu1804
docker_mongo | 2020-02-07T14:45:26.464+0000 I CONTROL [initandlisten] distarch: x86_64
docker_mongo | 2020-02-07T14:45:26.464+0000 I CONTROL [initandlisten] target_arch: x86_64
docker_mongo | 2020-02-07T14:45:26.464+0000 I CONTROL [initandlisten] options: { net: { bindIp: "*", port: 27017 } }
docker_mongo | 2020-02-07T14:45:26.464+0000 I STORAGE [initandlisten] Detected data files in /data/db created by the 'wiredTiger' storage engine, so setting the active storage engine to 'wiredTiger'.
docker_mongo | 2020-02-07T14:45:26.464+0000 I STORAGE [initandlisten]
docker_mongo | 2020-02-07T14:45:26.464+0000 I STORAGE [initandlisten] ** WARNING: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine
docker_mongo | 2020-02-07T14:45:26.464+0000 I STORAGE [initandlisten] ** See http://dochub.mongodb.org/core/prodnotes-filesystem
docker_mongo | 2020-02-07T14:45:26.464+0000 I STORAGE [initandlisten] wiredtiger_open config: create,cache_size=7471M,cache_overflow=(file_max=0M),session_max=33000,eviction=(threads_min=4,threads_max=4),config_base=false,statistics=(fast),log=(enabled=true,archive=true,path=journal,compressor=snappy),file_manager=(close_idle_time=100000,close_scan_interval=10,close_handle_minimum=250),statistics_log=(wait=0),verbose=[recovery_progress,checkpoint_progress],
docker_mongo | 2020-02-07T14:45:26.877+0000 I STORAGE [initandlisten] WiredTiger message [1581086726:877548][1:0x7ff0c5201b00], txn-recover: Recovering log 36 through 37
docker_mongo | 2020-02-07T14:45:26.904+0000 I STORAGE [initandlisten] WiredTiger message [1581086726:904522][1:0x7ff0c5201b00], txn-recover: Recovering log 37 through 37
docker_mongo | 2020-02-07T14:45:26.950+0000 I STORAGE [initandlisten] WiredTiger message [1581086726:950147][1:0x7ff0c5201b00], txn-recover: Main recovery loop: starting at 36/5888 to 37/256
docker_mongo | 2020-02-07T14:45:27.008+0000 I STORAGE [initandlisten] WiredTiger message [1581086727:8723][1:0x7ff0c5201b00], txn-recover: Recovering log 36 through 37
docker_mongo | 2020-02-07T14:45:27.044+0000 I STORAGE [initandlisten] WiredTiger message [1581086727:44798][1:0x7ff0c5201b00], txn-recover: Recovering log 37 through 37
docker_mongo | 2020-02-07T14:45:27.075+0000 I STORAGE [initandlisten] WiredTiger message [1581086727:75209][1:0x7ff0c5201b00], txn-recover: Set global recovery timestamp: (0,0)
docker_mongo | 2020-02-07T14:45:27.102+0000 I RECOVERY [initandlisten] WiredTiger recoveryTimestamp. Ts: Timestamp(0, 0)
docker_mongo | 2020-02-07T14:45:27.106+0000 I STORAGE [initandlisten] Timestamp monitor starting
docker_mongo | 2020-02-07T14:45:27.109+0000 I CONTROL [initandlisten]
docker_mongo | 2020-02-07T14:45:27.110+0000 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database.
docker_mongo | 2020-02-07T14:45:27.110+0000 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted.
docker_mongo | 2020-02-07T14:45:27.110+0000 I CONTROL [initandlisten]
docker_mongo | 2020-02-07T14:45:27.112+0000 I SHARDING [initandlisten] Marking collection local.system.replset as collection version: <unsharded>
docker_mongo | 2020-02-07T14:45:27.114+0000 I STORAGE [initandlisten] Flow Control is enabled on this deployment.
docker_mongo | 2020-02-07T14:45:27.114+0000 I SHARDING [initandlisten] Marking collection admin.system.roles as collection version: <unsharded>
docker_mongo | 2020-02-07T14:45:27.114+0000 I SHARDING [initandlisten] Marking collection admin.system.version as collection version: <unsharded>
docker_mongo | 2020-02-07T14:45:27.116+0000 I SHARDING [initandlisten] Marking collection local.startup_log as collection version: <unsharded>
docker_mongo | 2020-02-07T14:45:27.116+0000 I FTDC [initandlisten] Initializing full-time diagnostic data capture with directory '/data/db/diagnostic.data'
docker_mongo | 2020-02-07T14:45:27.118+0000 I SHARDING [LogicalSessionCacheRefresh] Marking collection config.system.sessions as collection version: <unsharded>
docker_mongo | 2020-02-07T14:45:27.118+0000 I NETWORK [initandlisten] Listening on /tmp/mongodb-27017.sock
docker_mongo | 2020-02-07T14:45:27.118+0000 I NETWORK [initandlisten] Listening on 0.0.0.0
docker_mongo | 2020-02-07T14:45:27.118+0000 I SHARDING [LogicalSessionCacheReap] Marking collection config.transactions as collection version: <unsharded>
docker_mongo | 2020-02-07T14:45:27.118+0000 I NETWORK [initandlisten] waiting for connections on port 27017
docker_spring |
docker_spring | . ____ _ __ _ _
docker_spring | /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
docker_spring | ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
docker_spring | \\/ ___)| |_)| | | | | || (_| | ) ) ) )
docker_spring | ' |____| .__|_| |_|_| |_\__, | / / / /
docker_spring | =========|_|==============|___/=/_/_/_/
docker_spring | :: Spring Boot :: (v2.2.1.RELEASE)
docker_spring |
docker_spring | 2020-02-07 14:45:27.552 INFO 1 --- [ main] com.example.demo.MainClass : Starting MainClass v0.0.1-SNAPSHOT on spring with PID 1 (/tmp/app.jar started by root in /)
docker_spring | 2020-02-07 14:45:27.556 INFO 1 --- [ main] com.example.demo.MainClass : No active profile set, falling back to default profiles: default
docker_spring | 2020-02-07 14:45:27.950 INFO 1 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data repositories in DEFAULT mode.
docker_spring | 2020-02-07 14:45:27.992 INFO 1 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 38ms. Found 1 repository interfaces.
docker_mongo | 2020-02-07T14:45:28.000+0000 I SHARDING [ftdc] Marking collection local.oplog.rs as collection version: <unsharded>
docker_spring | 2020-02-07 14:45:28.364 INFO 1 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
docker_spring | 2020-02-07 14:45:28.372 INFO 1 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
docker_spring | 2020-02-07 14:45:28.372 INFO 1 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.27]
docker_spring | 2020-02-07 14:45:28.425 INFO 1 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
docker_spring | 2020-02-07 14:45:28.426 INFO 1 --- [ main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 822 ms
docker_spring | 2020-02-07 14:45:28.616 INFO 1 --- [ main] org.mongodb.driver.cluster : Cluster created with settings {hosts=[docker_mongo:27017], mode=SINGLE, requiredClusterType=UNKNOWN, serverSelectionTimeout='30000 ms', maxWaitQueueSize=500}
docker_mongo | 2020-02-07T14:45:28.643+0000 I NETWORK [listener] connection accepted from 192.168.0.3:53260 #1 (1 connection now open)
docker_mongo | 2020-02-07T14:45:28.649+0000 I NETWORK [conn1] received client metadata from 192.168.0.3:53260 conn1: { driver: { name: "mongo-java-driver|legacy", version: "3.11.2" }, os: { type: "Linux", name: "Linux", architecture: "amd64", version: "5.3.0-28-generic" }, platform: "Java/Oracle Corporation/11.0.6+10" }
docker_spring | 2020-02-07 14:45:28.659 INFO 1 --- [ker_mongo:27017] org.mongodb.driver.connection : Opened connection [connectionId{localValue:1, serverValue:1}] to docker_mongo:27017
docker_spring | 2020-02-07 14:45:28.663 INFO 1 --- [ker_mongo:27017] org.mongodb.driver.cluster : Monitor thread successfully connected to server with description ServerDescription{address=docker_mongo:27017, type=STANDALONE, state=CONNECTED, ok=true, version=ServerVersion{versionList=[4, 2, 2]}, minWireVersion=0, maxWireVersion=8, maxDocumentSize=16777216, logicalSessionTimeoutMinutes=30, roundTripTimeNanos=2669943}
docker_spring | 2020-02-07 14:45:28.703 WARN 1 --- [ main] o.s.data.convert.CustomConversions : Registering converter from class java.time.LocalDateTime to class java.time.Instant as reading converter although it doesn't convert from a store-supported type! You might wanna check you annotation setup at the converter implementation.
docker_spring | 2020-02-07 14:45:28.703 WARN 1 --- [ main] o.s.data.convert.CustomConversions : Registering converter from class java.time.Instant to class java.time.LocalDateTime as reading converter although it doesn't convert from a store-supported type! You might wanna check you annotation setup at the converter implementation.
docker_spring | 2020-02-07 14:45:28.717 WARN 1 --- [ main] o.s.data.convert.CustomConversions : Registering converter from class java.time.LocalDateTime to class java.time.Instant as reading converter although it doesn't convert from a store-supported type! You might wanna check you annotation setup at the converter implementation.
docker_spring | 2020-02-07 14:45:28.717 WARN 1 --- [ main] o.s.data.convert.CustomConversions : Registering converter from class java.time.Instant to class java.time.LocalDateTime as reading converter although it doesn't convert from a store-supported type! You might wanna check you annotation setup at the converter implementation.
docker_spring | 2020-02-07 14:45:28.951 INFO 1 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
docker_spring | 2020-02-07 14:45:29.076 INFO 1 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
docker_spring | 2020-02-07 14:45:29.078 INFO 1 --- [ main] com.example.demo.MainClass : Started MainClass in 1.787 seconds (JVM running for 2.142)
docker_spring | 2020-02-07 14:45:29.081 INFO 1 --- [ main] org.mongodb.driver.cluster : Cluster created with settings {hosts=[localhost:27017], mode=SINGLE, requiredClusterType=UNKNOWN, serverSelectionTimeout='30000 ms', maxWaitQueueSize=500}
docker_spring | 2020-02-07 14:45:29.083 WARN 1 --- [ main] o.s.data.convert.CustomConversions : Registering converter from class java.time.LocalDateTime to class java.time.Instant as reading converter although it doesn't convert from a store-supported type! You might wanna check you annotation setup at the converter implementation.
docker_spring | 2020-02-07 14:45:29.083 WARN 1 --- [ main] o.s.data.convert.CustomConversions : Registering converter from class java.time.Instant to class java.time.LocalDateTime as reading converter although it doesn't convert from a store-supported type! You might wanna check you annotation setup at the converter implementation.
docker_spring | 2020-02-07 14:45:29.085 WARN 1 --- [ main] o.s.data.convert.CustomConversions : Registering converter from class java.time.LocalDateTime to class java.time.Instant as reading converter although it doesn't convert from a store-supported type! You might wanna check you annotation setup at the converter implementation.
docker_spring | 2020-02-07 14:45:29.085 WARN 1 --- [ main] o.s.data.convert.CustomConversions : Registering converter from class java.time.Instant to class java.time.LocalDateTime as reading converter although it doesn't convert from a store-supported type! You might wanna check you annotation setup at the converter implementation.
docker_spring | 2020-02-07 14:45:29.086 INFO 1 --- [localhost:27017] org.mongodb.driver.cluster : Exception in monitor thread while connecting to server localhost:27017
docker_spring |
docker_spring | com.mongodb.MongoSocketOpenException: Exception opening socket
docker_spring | at com.mongodb.internal.connection.SocketStream.open(SocketStream.java:70) ~[mongodb-driver-core-3.11.2.jar!/:na]
docker_spring | at com.mongodb.internal.connection.InternalStreamConnection.open(InternalStreamConnection.java:128) ~[mongodb-driver-core-3.11.2.jar!/:na]
docker_spring | at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:117) ~[mongodb-driver-core-3.11.2.jar!/:na]
docker_spring | at java.base/java.lang.Thread.run(Thread.java:834) ~[na:na]
docker_spring | Caused by: java.net.ConnectException: Connection refused (Connection refused)
docker_spring | at java.base/java.net.PlainSocketImpl.socketConnect(Native Method) ~[na:na]
docker_spring | at java.base/java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:399) ~[na:na]
docker_spring | at java.base/java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:242) ~[na:na]
docker_spring | at java.base/java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:224) ~[na:na]
docker_spring | at java.base/java.net.SocksSocketImpl.connect(SocksSocketImpl.java:403) ~[na:na]
docker_spring | at java.base/java.net.Socket.connect(Socket.java:609) ~[na:na]
docker_spring | at com.mongodb.internal.connection.SocketStreamHelper.initialize(SocketStreamHelper.java:64) ~[mongodb-driver-core-3.11.2.jar!/:na]
docker_spring | at com.mongodb.internal.connection.SocketStream.initializeSocket(SocketStream.java:79) ~[mongodb-driver-core-3.11.2.jar!/:na]
docker_spring | at com.mongodb.internal.connection.SocketStream.open(SocketStream.java:65) ~[mongodb-driver-core-3.11.2.jar!/:na]
docker_spring | ... 3 common frames omitted
docker_spring |
docker_spring | 2020-02-07 14:45:29.119 INFO 1 --- [ main] org.mongodb.driver.cluster : Cluster description not yet available. Waiting for 30000 ms before timing out
docker_spring | 2020-02-07 14:45:59.125 INFO 1 --- [ main] ConditionEvaluationReportLoggingListener :
docker_spring |
docker_spring | Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
docker_spring | 2020-02-07 14:45:59.131 ERROR 1 --- [ main] o.s.boot.SpringApplication : Application run failed
docker_spring |
docker_spring | java.lang.IllegalStateException: Failed to execute CommandLineRunner
docker_spring | at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:787) ~[spring-boot-2.2.1.RELEASE.jar!/:2.2.1.RELEASE]
docker_spring | at org.springframework.boot.SpringApplication.callRunners(SpringApplication.java:768) ~[spring-boot-2.2.1.RELEASE.jar!/:2.2.1.RELEASE]
docker_spring | at org.springframework.boot.SpringApplication.run(SpringApplication.java:322) ~[spring-boot-2.2.1.RELEASE.jar!/:2.2.1.RELEASE]
docker_spring | at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226) ~[spring-boot-2.2.1.RELEASE.jar!/:2.2.1.RELEASE]
docker_spring | at org.springframework.boot.SpringApplication.run(SpringApplication.java:1215) ~[spring-boot-2.2.1.RELEASE.jar!/:2.2.1.RELEASE]
docker_spring | at com.example.demo.MainClass.main(MainClass.java:8) ~[classes!/:0.0.1-SNAPSHOT]
docker_spring | at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
docker_spring | at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:na]
docker_spring | at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
docker_spring | at java.base/java.lang.reflect.Method.invoke(Method.java:566) ~[na:na]
docker_spring | at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48) ~[app.jar:0.0.1-SNAPSHOT]
docker_spring | at org.springframework.boot.loader.Launcher.launch(Launcher.java:87) ~[app.jar:0.0.1-SNAPSHOT]
docker_spring | at org.springframework.boot.loader.Launcher.launch(Launcher.java:51) ~[app.jar:0.0.1-SNAPSHOT]
docker_spring | at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:52) ~[app.jar:0.0.1-SNAPSHOT]
docker_spring | Caused by: org.springframework.dao.DataAccessResourceFailureException: Timed out after 30000 ms while waiting to connect. Client view of cluster state is {type=UNKNOWN, servers=[{address=localhost:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketOpenException: Exception opening socket}, caused by {java.net.ConnectException: Connection refused (Connection refused)}}]; nested exception is com.mongodb.MongoTimeoutException: Timed out after 30000 ms while waiting to connect. Client view of cluster state is {type=UNKNOWN, servers=[{address=localhost:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketOpenException: Exception opening socket}, caused by {java.net.ConnectException: Connection refused (Connection refused)}}]
docker_spring | at org.springframework.data.mongodb.core.MongoExceptionTranslator.translateExceptionIfPossible(MongoExceptionTranslator.java:90) ~[spring-data-mongodb-2.2.1.RELEASE.jar!/:2.2.1.RELEASE]
docker_spring | at org.springframework.data.mongodb.core.MongoTemplate.potentiallyConvertRuntimeException(MongoTemplate.java:2902) ~[spring-data-mongodb-2.2.1.RELEASE.jar!/:2.2.1.RELEASE]
docker_spring | at org.springframework.data.mongodb.core.MongoTemplate.execute(MongoTemplate.java:587) ~[spring-data-mongodb-2.2.1.RELEASE.jar!/:2.2.1.RELEASE]
docker_spring | at org.springframework.data.mongodb.core.MongoTemplate.insertDocument(MongoTemplate.java:1494) ~[spring-data-mongodb-2.2.1.RELEASE.jar!/:2.2.1.RELEASE]
docker_spring | at org.springframework.data.mongodb.core.MongoTemplate.doInsert(MongoTemplate.java:1294) ~[spring-data-mongodb-2.2.1.RELEASE.jar!/:2.2.1.RELEASE]
docker_spring | at org.springframework.data.mongodb.core.MongoTemplate.insert(MongoTemplate.java:1226) ~[spring-data-mongodb-2.2.1.RELEASE.jar!/:2.2.1.RELEASE]
docker_spring | at org.springframework.data.mongodb.core.MongoTemplate.insert(MongoTemplate.java:1211) ~[spring-data-mongodb-2.2.1.RELEASE.jar!/:2.2.1.RELEASE]
docker_spring | at com.example.demo.DemoApplication.run(DemoApplication.java:40) ~[classes!/:0.0.1-SNAPSHOT]
docker_spring | at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:784) ~[spring-boot-2.2.1.RELEASE.jar!/:2.2.1.RELEASE]
docker_spring | ... 13 common frames omitted
docker_spring | Caused by: com.mongodb.MongoTimeoutException: Timed out after 30000 ms while waiting to connect. Client view of cluster state is {type=UNKNOWN, servers=[{address=localhost:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketOpenException: Exception opening socket}, caused by {java.net.ConnectException: Connection refused (Connection refused)}}]
docker_spring | at com.mongodb.internal.connection.BaseCluster.getDescription(BaseCluster.java:182) ~[mongodb-driver-core-3.11.2.jar!/:na]
docker_spring | at com.mongodb.internal.connection.SingleServerCluster.getDescription(SingleServerCluster.java:41) ~[mongodb-driver-core-3.11.2.jar!/:na]
docker_spring | at com.mongodb.client.internal.MongoClientDelegate.getConnectedClusterDescription(MongoClientDelegate.java:145) ~[mongodb-driver-3.11.2.jar!/:na]
docker_spring | at com.mongodb.client.internal.MongoClientDelegate.createClientSession(MongoClientDelegate.java:100) ~[mongodb-driver-3.11.2.jar!/:na]
docker_spring | at com.mongodb.client.internal.MongoClientDelegate$DelegateOperationExecutor.getClientSession(MongoClientDelegate.java:277) ~[mongodb-driver-3.11.2.jar!/:na]
docker_spring | at com.mongodb.client.internal.MongoClientDelegate$DelegateOperationExecutor.execute(MongoClientDelegate.java:201) ~[mongodb-driver-3.11.2.jar!/:na]
docker_spring | at com.mongodb.client.internal.MongoCollectionImpl.executeSingleWriteRequest(MongoCollectionImpl.java:1048) ~[mongodb-driver-3.11.2.jar!/:na]
docker_spring | at com.mongodb.client.internal.MongoCollectionImpl.executeInsertOne(MongoCollectionImpl.java:498) ~[mongodb-driver-3.11.2.jar!/:na]
docker_spring | at com.mongodb.client.internal.MongoCollectionImpl.insertOne(MongoCollectionImpl.java:482) ~[mongodb-driver-3.11.2.jar!/:na]
docker_spring | at com.mongodb.client.internal.MongoCollectionImpl.insertOne(MongoCollectionImpl.java:476) ~[mongodb-driver-3.11.2.jar!/:na]
docker_spring | at org.springframework.data.mongodb.core.MongoTemplate.lambda$insertDocument$16(MongoTemplate.java:1500) ~[spring-data-mongodb-2.2.1.RELEASE.jar!/:2.2.1.RELEASE]
docker_spring | at org.springframework.data.mongodb.core.MongoTemplate.execute(MongoTemplate.java:585) ~[spring-data-mongodb-2.2.1.RELEASE.jar!/:2.2.1.RELEASE]
docker_spring | ... 19 common frames omitted
docker_spring |
docker_spring | 2020-02-07 14:45:59.140 INFO 1 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Shutting down ExecutorService 'applicationTaskExecutor'
docker_mongo | 2020-02-07T14:45:59.146+0000 I NETWORK [conn1] end connection 192.168.0.3:53260 (0 connections now open)
docker_spring exited with code 1
最佳答案
很简单
MongoClients.create()
without any parameters to connect to a MongoDB instance running on localhost on port 27017.
docker_spring | 2020-02-07 14:45:28.616 INFO 1 --- [ main] org.mongodb.driver.cluster : Cluster created with settings {hosts=[docker_mongo:27017], mode=SINGLE, requiredClusterType=UNKNOWN, serverSelectionTimeout='30000 ms', maxWaitQueueSize=500}
docker_mongo | 2020-02-07T14:45:28.643+0000 I NETWORK [listener] connection accepted from 192.168.0.3:53260 #1 (1 connection now open)
docker_mongo | 2020-02-07T14:45:28.649+0000 I NETWORK [conn1] received client metadata from 192.168.0.3:53260 conn1: { driver: { name: "mongo-java-driver|legacy", version: "3.11.2" }, os: { type: "Linux", name: "Linux", architecture: "amd64", version: "5.3.0-28-generic" }, platform: "Java/Oracle Corporation/11.0.6+10" }
docker_spring | 2020-02-07 14:45:28.659 INFO 1 --- [ker_mongo:27017] org.mongodb.driver.connection : Opened connection [connectionId{localValue:1, serverValue:1}] to docker_mongo:27017
docker_spring | 2020-02-07 14:45:28.663 INFO 1 --- [ker_mongo:27017] org.mongodb.driver.cluster : Monitor thread successfully connected to server with description ServerDescription{address=docker_mongo:27017, type=STANDALONE, state=CONNECTED, ok=true, version=ServerVersion{versionList=[4, 2, 2]}, minWireVersion=0, maxWireVersion=8, maxDocumentSize=16777216, logicalSessionTimeoutMinutes=30, roundTripTimeNanos=2669943}
@SpringBootApplication
@ComponentScan({"com.example.client","com.example.demo","com.example.model"})
public class DemoApplication implements CommandLineRunner {
@Autowired
private MongoOperations mongoOps;
@Override
public void run(String... args) throws Exception {
mongoOps.insert(new Expenditure("Aldi",10.01, LocalDate.parse("2019-10-05")));
System.out.println(mongoOps.findOne(new Query(Criteria.where("name").is("Aldi")),Expenditure.class));
mongoOps.dropCollection("expenditure");
PopulateExpenditureDB.populateExpenditures(mongoOps);
}
}
关于spring - Spring Docker Container停止是因为它已尝试连接到localhost MongoDB,即使它已正确连接到MongoDB Container,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60116376/
我知道这个问题可能已经被问过,但我检查了所有这些,我认为我的情况有所不同(请友善)。所以我有两个数据集,第一个是测试数据集,第二个是我保存在数据框中的预测(预测值,这就是没有数据列的原因)。我想合并两
在 .loc 方法的帮助下,我根据同一数据框中另一列中的值来识别 Panda 数据框中某一列中的值。 下面给出了代码片段供您引用: var1 = output_df['Player'].loc[out
当我在 Windows 中使用 WinSCP 通过 Ubuntu 连接到 VMware 时,它提示: The server rejected SFTP connection, but it lis
我正在开发一个使用 xml web 服务的 android 应用程序。在 wi-fi 网络中连接时工作正常,但在 3G 网络中连接时失败(未找到 http 404)。 这不仅仅发生在设备中。为了进行测
我有一个XIB包含我的控件的文件,加载到 Interface Builder(Snow Leopard 上的 Xcode 4.0.2)中。 文件的所有者被设置为 someClassController
我在本地计算机上管理 MySQL 数据库,并通过运行以下程序通过 C 连接到它: #include #include #include int main(int argc, char** arg
我不知道为什么每次有人访问我网站上的页面时,都会打开一个与数据库的新连接。最终我到达了大约 300 并收到错误并且页面不再加载。我认为它应该工作的方式是,我将 maxIdle 设置为 30,这意味着
希望清理 NMEA GPS 中的 .txt 文件。我当前的代码如下。 deletes = ['$GPGGA', '$GPGSA', '$GPGSV', '$PSRF156', ] searchquer
我有一个 URL、一个用户名和一个密码。我想在 C# .Net WinForms 中建立 VPN 连接。 你能告诉我从哪里开始吗?任何第三方 API? 代码示例将受到高度赞赏... 最佳答案 您可以像
有没有更好的方法将字符串 vector 转换为字符 vector ,字符串之间的终止符为零。 因此,如果我有一个包含以下字符串的 vector "test","my","string",那么我想接收一
我正在编写一个库,它不断检查 android 设备的连接,并在设备连接、断开连接或互联网连接变慢时给出回调。 https://github.com/muddassir235/connection_ch
我的操作系统:Centos 7 + CLOUDLINUX 7.7当我尝试从服务器登录Mysql时 [root@server3 ~]# Mysql -u root -h localhost -P 330
我收到错误:Puma 发现此错误:无法打开到本地主机的 TCP 连接:9200(连接被拒绝 - 连接(2)用于“本地主机”端口 9200)(Faraday::ConnectionFailed)在我的
请给我一些解决以下错误的方法。 这是一个聊天应用....代码和错误如下:: conversations_controller.rb def create if Conversation.bet
我想将两个单元格中的数据连接到一个单元格中。我还想只组合那些具有相同 ID 的单元格。 任务 ID 名称 4355.2 参与者 4355.2 领袖 4462.1 在线 4462.1 快速 4597.1
我经常需要连接 TSQL 中的字段... 使用“+”运算符时 TSQL 强制您处理的两个问题是 Data Type Precedence和 NULL 值。 使用数据类型优先级,问题是转换错误。 1)
有没有在 iPad 或 iPhone 应用程序中使用 Facebook 连接。 这个想法是登录这个应用程序,然后能够看到我的哪些 facebook 用户也在使用该应用程序及其功能。 最佳答案 是的。
我在连接或打印字符串时遇到了一个奇怪的问题。我有一个 char * ,可以将其设置为字符串文字的几个值之一。 char *myStrLiteral = NULL; ... if(blah) myS
对于以下数据 - let $x := "Yahooooo !!!! Select one number - " let $y := 1 2 3 4 5 6 7 我想得到
我正在看 UDEMY for perl 的培训视频,但是视频不清晰,看起来有错误。 培训展示了如何使用以下示例连接 2 个字符串: #!usr/bin/perl print $str = "Hi";
我是一名优秀的程序员,十分优秀!