Not able to establish connection between mongodb and Springboot through app.properties file

705 Views Asked by At

I want to establish connection with mongodb through app.properties files in Spring boot. Currently, I am establishing connection through Uri variable declared in the class file itself.

private static String uri ="mongodb://localhost:27017/?readPreference=primary&appname=MongoDB%20Compass&directConnection=true&ssl=false";

private static String database = "xyz";

When I am trying to configure it in app.properties files like this

spring.data.mongodb.uri= mongodb://localhost:27017/?readPreference=primary&appname=MongoDB%20Compass&directConnection=true&ssl=false
spring.data.mongodb.database = xyz

It is not connecting and I am getting this error

Cannot invoke "String.startsWith(String)" because "connectionString" is null
0

There are 0 best solutions below