2

No matter what I try, I cannot disable auto-configuration of spring-data-mongodb-reactive.

Properties

spring:
  profiles: dev
  data:
    mongodb:
      uri: "mongodb://user:[email protected]:27017/my-db"
      repositories:
        type: reactive
      authentication-database: admin

Repository

@Repository
interface IMembersRepository: ReactiveMongoRepository<Member, String> {}

MongoConfig

@Configuration
@EnableReactiveMongoRepositories(basePackages = ["com.my.package.repository"])
class MongoConfig : AbstractReactiveMongoConfiguration() {

    override fun reactiveMongoClient(): MongoClient = mongoClient()

    override fun getDatabaseName(): String = "my-db"

    @Bean()
    fun mongoClient() = MongoClients.create()

    @Bean()
    override fun reactiveMongoTemplate() = ReactiveMongoTemplate(mongoClient(), databaseName)
}

AppConfig

@Configuration
@EnableWebFlux
@ComponentScan("com.my.package")
class AppConfig: WebFluxConfigurer {
    override fun addCorsMappings(registry: CorsRegistry) {
        registry.addMapping("api/**")
    }
}

SpringBootApplication

@SpringBootApplication(exclude = [
    MongoReactiveAutoConfiguration::class,
    MongoReactiveDataAutoConfiguration::class,
    MongoReactiveRepositoriesAutoConfiguration::class,
    MongoAutoConfiguration::class,
    MongoDataAutoConfiguration::class,
    MongoRepositoriesAutoConfiguration::class,
    EmbeddedMongoAutoConfiguration::class
])
class AstridServerApplication

fun main(args: Array<String>) {
    runApplication<AstridServerApplication>(*args)
}

As you can see, I even went as far as disabling all available MongoDB auto-configs, and Boot still tries to establish connection to a local instance, which I do not have. But I did also try different combinations.

[localhost:27017] org.mongodb.driver.cluster               : Exception in monitor thread while connecting to server localhost:27017

com.mongodb.MongoSocketOpenException: Exception opening socket
    at com.mongodb.internal.connection.AsynchronousSocketChannelStream$OpenCompletionHandler.failed(AsynchronousSocketChannelStream.java:117) ~[mongodb-driver-core-3.11.2.jar:na]
    at java.base/sun.nio.ch.Invoker.invokeUnchecked(Invoker.java:129) ~[na:na]
    at java.base/sun.nio.ch.Invoker.invokeDirect(Invoker.java:158) ~[na:na]
    at java.base/sun.nio.ch.Invoker.invoke(Invoker.java:186) ~[na:na]
    at java.base/sun.nio.ch.Invoker.invoke(Invoker.java:298) ~[na:na]
    at java.base/sun.nio.ch.WindowsAsynchronousSocketChannelImpl$ConnectTask.failed(WindowsAsynchronousSocketChannelImpl.java:308) ~[na:na]
    at java.base/sun.nio.ch.Iocp$EventHandlerTask.run(Iocp.java:389) ~[na:na]
    at java.base/sun.nio.ch.AsynchronousChannelGroupImpl$1.run(AsynchronousChannelGroupImpl.java:112) ~[na:na]
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130) ~[na:na]
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:630) ~[na:na]
    at java.base/java.lang.Thread.run(Thread.java:832) ~[na:na]
Caused by: java.io.IOException: The remote computer refused the network connection
    at java.base/sun.nio.ch.Iocp.translateErrorToIOException(Iocp.java:299) ~[na:na]
    ... 5 common frames omitted

2 Answers 2

1

The client is connecting to the default address. I would focus on understanding why your config file isn't taking effect rather than on "disabling auto-configuration". The behavior you are seeing is consistent with the client not receiving any external configuration and using its built-in defaults.

Sign up to request clarification or add additional context in comments.

1 Comment

I do end up with connection to the external DB. But I also end up with a failed local connection because I have no local DB. I do not want this behavior, just external connection.
0

In the spring-autoconfigure-metadata.properties I found a list of fields you can specify.

Since I needed to override the code in AbstractReactiveMongoConfiguration (there are other classes if you are not using reactive)

I just extended the class and pointed to it like this org.springframework.boot.autoconfigure.mongo. MongoReactiveAutoConfiguration="mypackage.MyCustomAbstractReactiveMongoConfiguration"

No need to exclude anything (which wasn't really possible)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.