Skip to content

Mongo auto-configuration fails when username or password properties contains a colon (:) or at-sign (@) #36261

@mbreevoort

Description

@mbreevoort

Spring boot version: 3.1.1
Problem: Error when we have : in our password for MongoDB

[org/springframework/boot/autoconfigure/mongo/MongoAutoConfiguration$MongoClientSettingsConfiguration.class]: Failed to instantiate [org.springframework.boot.autoconfigure.mongo.StandardMongoClientSettingsBuilderCustomizer]: Factory method 'standardMongoSettingsCustomizer' threw exception with message: The connection string contains invalid user information. If the username or password contains a colon (:) or an at-sign (@) then it must be urlencoded

This exception is thrown by com.mongodb.ConnectionString line 339 of mongodb-driver-core-4.9.1.jar

A solution is to url encode (java.net.URLEncoder) the username and password in:
https://github.com/spring-projects/spring-boot/blob/v3.1.1/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mongo/PropertiesMongoConnectionDetails.java#L52

Metadata

Metadata

Assignees

Labels

type: regressionA regression from a previous release

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions