Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I can't exclude MongoAutoConfiguration in Springboot-Kotlin (MongoSocketOpenException)

enter image description here

I'm getting a MongoSocketOpenException when trying to exclude MongoAutoConfiguration. I'm trying to connect to a remote MongoDB. Is the @EnableAutoConfiguration syntax correct considering I'm working in Kotlin?

Exception:

com.mongodb.MongoSocketOpenException: Exception opening socket
        at com.mongodb.connection.SocketStream.open(SocketStream.java:63) ~[mongo-java-driver-3.4.2.jar:na]
        at com.mongodb.connection.InternalStreamConnection.open(InternalStreamConnection.java:115) ~[mongo-java-driver-3.4.2.
jar:na]
        at com.mongodb.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:113) ~[mongo-java-
driver-3.4.2.jar:na]
        at java.lang.Thread.run(Thread.java:745) [na:1.8.0_20]
Caused by: java.net.ConnectException: Connection refused: connect
        at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method) ~[na:1.8.0_20]
        at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:85) ~[na:1.8.0_20]
        at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:345) ~[na:1.8.0_20]
        at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206) ~[na:1.8.0_20]
        at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188) ~[na:1.8.0_20]
        at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172) ~[na:1.8.0_20]
        at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392) ~[na:1.8.0_20]
        at java.net.Socket.connect(Socket.java:589) ~[na:1.8.0_20]
        at com.mongodb.connection.SocketStreamHelper.initialize(SocketStreamHelper.java:57) ~[mongo-java-driver-3.4.2.jar:na]

        at com.mongodb.connection.SocketStream.open(SocketStream.java:58) ~[mongo-java-driver-3.4.2.jar:na]
        ... 3 common frames omitted
like image 762
Martin Erlic Avatar asked Sep 18 '17 14:09

Martin Erlic


2 Answers

Its better this way

@EnableAutoConfiguration(exclude = [MongoAutoConfiguration::class])
like image 104
Eric Avatar answered Oct 10 '22 04:10

Eric


There's no java-like array initialization in Kotlin. It should be

@EnableAutoConfiguration(exclude = arrayOf(MongoAutoConfiguration::class))
like image 20
Alexander Romanov Avatar answered Oct 10 '22 04:10

Alexander Romanov