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
This question is related to
java
spring
mongodb
spring-boot
spring-data-jpa
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.
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
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>
Add the line below in application.properties file under resource folder and restart your application.
spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration
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> -->
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
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>
adding org.apache.derby dependency solved my issue.
<dependency>
<groupId>org.apache.derby</groupId>
<artifactId>derby</artifactId>
<scope>runtime</scope>
</dependency>
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.
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
@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'
Source: Stackoverflow.com