美文网首页java专题Java 杂谈
springboot禁用mongo配置

springboot禁用mongo配置

作者: H_Man | 来源:发表于2018-11-06 10:28 被阅读0次

    springboot内置了mongo驱动,默认配置localhost:27017,若本机没有配置mongoDB,则会连接失败。报错。

    com.mongodb.MongoSocketOpenException: Exception opening socket
        at com.mongodb.connection.SocketStream.open(SocketStream.java:63) ~[mongo-java-driver-3.2.2.jar!/:na]
        at com.mongodb.connection.InternalStreamConnection.open(InternalStreamConnection.java:114) ~[mongo-java-driver-3.2.2.jar!/:na]
        at com.mongodb.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:128) ~[mongo-java-driver-3.2.2.jar!/:na]
        at java.lang.Thread.run(Thread.java:745) [na:1.8.0_102]
    Caused by: java.net.ConnectException: Connection refused
        at java.net.PlainSocketImpl.socketConnect(Native Method) ~[na:1.8.0_102]
        at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350) ~[na:1.8.0_102]
        at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206) ~[na:1.8.0_102]
        at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188) ~[na:1.8.0_102]
        at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392) ~[na:1.8.0_102]
        at java.net.Socket.connect(Socket.java:589) ~[na:1.8.0_102]
        at com.mongodb.connection.SocketStreamHelper.initialize(SocketStreamHelper.java:50) ~[mongo-java-driver-3.2.2.jar!/:na]
        at com.mongodb.connection.SocketStream.open(SocketStream.java:58) ~[mongo-java-driver-3.2.2.jar!/:na]
        ... 3 common frames omitted
    

    解决方法:
    springbootapplication注解上面声明取消mongo自动配置

    @SpringBootApplication(exclude = {MongoAutoConfiguration.class, MongoDataAutoConfiguration.class})
    

    相关文章

      网友评论

        本文标题:springboot禁用mongo配置

        本文链接:https://www.haomeiwen.com/subject/xwvyxqtx.html