56

I have created a basic spring boot application from SPRING INITIALIZR with the Web, MongoDB and JPA dependencies.

When I try to run the spring boot application I am getting the following exception:

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled. 2018-03-25 16:27:02.807 ERROR 16256 --- [ restartedMain] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPLICATION FAILED TO START *************************** Description: Failed to auto-configure a DataSource: 'spring.datasource.url' is not specified and no embedded datasource could be auto-configured. Reason: Failed to determine a suitable driver class Action: Consider the following situation: If you want an embedded database like H2, HSQL or Derby, please add it in the Classpath. If you have database settings to be loaded from a particular profile you may need to activate it since no profiles were currently active. 

In application.properties file I am having the following configuration:

server.port=8081 spring.data.mongodb.database=TestDatabase spring.data.mongodb.host=localhost spring.data.mongodb.port=27017 

Versions which I use: Spring : 5.0.4, MongoDB : 3.6, Spring Boot: 2.0

14 Answers 14

123

Since you have added both mongodb and data-jpa dependencies in your pom.xml file, it was creating a dependency conflict like below

<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jpa</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-mongodb</artifactId> </dependency> 

Try removing jpa dependency and run. It should work fine.

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

10 Comments

Yes that was my problem. I have removed the JPA dependency and it works fine now. Thank you.
Please note also spring-boot-starter-batch introduces a dependency to jdbc which activates this same error
Yes that solved my problem. In my case was org.postgresql:postgresql and data-jpa. Just exclude data-jpa and all is fine.
Would it have created an error if I had data-jpa and mysql-connector-java in my pom.xml?
I hided the mongo db dependency but still had the same problem.
|
64

Go to resources folder where the application.properties is present, update the below code in that.

spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration 

3 Comments

I have got this problem even i didn't use jpa and mongodb dependencies together in my pom.xml... So i am getting it cuz spring-boot-starter-batch dependency. Can you please explain why this setting is work ?
It worked, but then i got error when sending request from client side: blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource
@AdirD That has nothing to do with the issue at hand, you need to set your server to accept CORS requests
22

Add the line below in application.properties file under resource folder and restart your application.

spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration 

Comments

3

I encountered this error simply because I misspelled the spring.datasource.url value in the application.properties file and I was using postgresql:

Problem was: jdbc:postgres://localhost:<port-number>/<database-name>

Fixed to: jdbc:postgresql://localhost:<port-number>/<database-name>

NOTE: the difference is postgres & postgresql, the two are 2 different things.

Further causes and solutions may be found here

Comments

2

Seems there is missing MongoDB driver. Include the following dependency to pom.xml:

<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-mongodb</artifactId> </dependency> 

2 Comments

Thanks for the answer. I already have this dependency in my pom.xml file. Still failing.
it failed for me too with spring-boot-starter-data-mongodb & spring-batch-starter
2

your dependency based on data is trying to find their respective entities which one has not been created, comments the dependencies based on data and runs the app again.

<!-- <dependency> --> <!-- <groupId>org.springframework.boot</groupId> --> <!-- <artifactId>spring-boot-starter-data-jpa</artifactId> --> <!-- </dependency> --> 

Comments

1

This error occurred when you are putting JPA dependencies in your spring-boot configuration file like in maven or gradle. The solution is: Spring-Boot Documentation

You have to specify the DB connection string and driver details in application.properties file. This will solve the issue. This might help to someone.

Comments

1

if anyone is here after facing this issue
when "project.jar" is generated
while every thing is fine when i the project is run in IDE / STS (spring tool suit).
here is a way out:

unnecessary spaces " " in the "application.yml" file can cause this.

server: port: 8085 spring: datasource: url: jdbc:mysql://localhost:3306/studentdb username: root password: root driver-class-name: com.mysql.cj.jdbc.Driver jpa: hibernate: ddl-auto: update show-sql: true database-platform: org.hibernate.dialect.MySQL5InnoDBDialect application: name: STUDENT-SERVICE 

instead of tweaking my "application.yml" file
i simply moved all my statements in "application.yml" file to
"application.properties" file and formatted the statements like required in ".properties".

spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver spring.datasource.url=jdbc:mysql://localhost:3306/studentdb spring.datasource.username=root spring.datasource.password=root spring.jpa.hibernate.ddl-auto = update spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect spring.jpa.show-sql=true spring.jpa.properties.hibernate.format.sql=true spring.application.name=student-service server.port=8085 

and voilà

1 Comment

I also faced with the problem, after changed packaging from war to jar. I have an application.properties file which has a profile value and then application-profileName.properties file is used to get db connection parameters. Interestingly, when works after changed back to war.
0

Add your dependencies like mongodb,web,jpa. Delete/clear the remainings.

<dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-mongodb</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> </dependencies> 

Comments

0

In gradle build i simply:

compile('org.springframework.boot:spring-boot-starter-data-jpa') compile('org.springframework.boot:spring-boot-starter-security') compile('org.springframework.boot:spring-boot-starter-web') compile('org.springframework.boot:spring-boot-devtools')

removed

**`compile('org.springframework.boot:spring-boot-starter-data-jpa')`** 

and it worked for me.

Comments

0

@Bhabadyuti Bal give us a good answer, in gradle you can use :

compile 'org.springframework.boot:spring-boot-starter-data-jpa' compile 'com.h2database:h2' 

in test time :

testCompile 'org.reactivecommons.utils:object-mapper:0.1.0' testCompile 'com.h2database:h2' 

Comments

0

JWT settings in applications.properties generate this error.

Ex: #ConfigJWT jwt.secret=seuSegredoJWT jwt.expiration=86400 

Remove this configurations, if you use this configurations, go remove and your code will it run.

Comments

-1

adding org.apache.derby dependency solved my issue.

<dependency> <groupId>org.apache.derby</groupId> <artifactId>derby</artifactId> <scope>runtime</scope> </dependency> 

Comments

-1

I ran into this problem when I simply mistyped my jdbc url in application.properties. Hope this helps someone: before:

spring.datasource.url=jdbc://localhost:3306/test 

after:

spring.datasource.url=jdbc:mysql://localhost:3306/test 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.