After creating springbootdemo, run the command to report the MongoSocketOpenException error solution,

Source: Internet
Author: User

After creating springbootdemo, run the command to report the MongoSocketOpenException error solution,

On the SpringbootdemoApplication class, right-click Run as and select Spring Boot App. Then, the Console outputs the following error log:

Com. mongodb. MongoSocketOpenException: Exception opening socket
At com. mongodb. connection. SocketStream. open (SocketStream. java: 63 )~ [Mongodb-driver-core-3.4.2.jar: na]
At com. mongodb. connection. InternalStreamConnection. open (InternalStreamConnection. java: 115 )~ [Mongodb-driver-core-3.4.2.jar: na]
At com. mongodb. connection. DefaultServerMonitor $ ServerMonitorRunnable. run (DefaultServerMonitor. java: 113 )~ [Mongodb-driver-core-3.4.2.jar: na]
At java. lang. Thread. run (Unknown Source) [na: 1.8.0 _ 91]
Caused by: java.net. ConnectException: Connection refused: connect
At java.net. DualStackPlainSocketImpl. waitForConnect (Native Method )~ [Na: 1.8.0 _ 91]
At java.net. DualStackPlainSocketImpl. socketConnect (Unknown Source )~ [Na: 1.8.0 _ 91]
At java.net. AbstractPlainSocketImpl. doConnect (Unknown Source )~ [Na: 1.8.0 _ 91]
At java.net. AbstractPlainSocketImpl. connectToAddress (Unknown Source )~ [Na: 1.8.0 _ 91]
At java.net. AbstractPlainSocketImpl. connect (Unknown Source )~ [Na: 1.8.0 _ 91]
At java.net. PlainSocketImpl. connect (Unknown Source )~ [Na: 1.8.0 _ 91]
At java.net. SocksSocketImpl. connect (Unknown Source )~ [Na: 1.8.0 _ 91]
At java.net. Socket. connect (Unknown Source )~ [Na: 1.8.0 _ 91]
At com. mongodb. connection. SocketStreamHelper. initialize (SocketStreamHelper. java: 57 )~ [Mongodb-driver-core-3.4.2.jar: na]
At com. mongodb. connection. SocketStream. open (SocketStream. java: 58 )~ [Mongodb-driver-core-3.4.2.jar: na]
... 3 common frames omitted

Go to Baidu and find an article stating that springboot is automatically configured to support mongodb. A mongo instance is automatically instantiated when spring boot is started. You need to disable automatic configuration,

Add@ SpringBootApplication (exclude = export autoconfiguration. class)The original Article is http://blog.csdn.net/xuyw#/article/details/72918360.

After I add annotations to the class, this error is solved, but a new error log is output, as shown below:

Java. lang. ClassCastException: org. springframework. boot. context. event. ApplicationFailedEvent cannot be cast to org. springframework. boot. web. context. WebServerInitializedEvent
At org. springframework. context. event. SimpleApplicationEventMulticaster. invokeListener (SimpleApplicationEventMulticaster. java: 159) [spring-context-5.0.0.RC3.jar: 5.0.0.RC3]
At org. springframework. context. event. SimpleApplicationEventMulticaster. multicastEvent (SimpleApplicationEventMulticaster. java: 139) [spring-context-5.0.0.RC3.jar: 5.0.0.RC3]
At org. springframework. context. event. SimpleApplicationEventMulticaster. multicastEvent (SimpleApplicationEventMulticaster. java: 127) [spring-context-5.0.0.RC3.jar: 5.0.0.RC3]
At org. springframework. boot. context. event. EventPublishingRunListener. finished (EventPublishingRunListener. java: 114) [spring-boot-2.0.0.M3.jar: 2.0.0.M3]
At org. springframework. boot. SpringApplicationRunListeners. callFinishedListener (SpringApplicationRunListeners. java: 79) [spring-boot-2.0.0.M3.jar: 2.0.0.M3]
At org. springframework. boot. SpringApplicationRunListeners. finished (SpringApplicationRunListeners. java: 72) [spring-boot-2.0.0.M3.jar: 2.0.0.M3]
At org. springframework. boot. SpringApplication. handleRunFailure (SpringApplication. java: 803) [spring-boot-2.0.0.M3.jar: 2.0.0.M3]
At org. springframework. boot. SpringApplication. run (SpringApplication. java: 338) [spring-boot-2.0.0.M3.jar: 2.0.0.M3]
At org. springframework. boot. SpringApplication. run (SpringApplication. java: 1245) [spring-boot-2.0.0.M3.jar: 2.0.0.M3]
At org. springframework. boot. SpringApplication. run (SpringApplication. java: 1233) [spring-boot-2.0.0.M3.jar: 2.0.0.M3]
At com. example. demo. SpringbootdemoApplication. main (SpringbootdemoApplication. java: 22) [classes/: na],

Copy the first line of Error Log and search for the answer on Google. You need to comment out the Mongo-related startup statement in the pom. xml file of the project, as shown below:

<! -- <Dependency>
<GroupId> org. springframework. boot </groupId>
<ArtifactId> spring-boot-starter-data-mongodb </artifactId>
</Dependency> -->

Save and restart. No error is reported. Link to the original github article: https://github.com/spring-projects/spring-boot/issues/10047.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.