Failed to auto-configure a DataSource: 'spring.datasource.url' is not specified

后端 未结 12 1589
逝去的感伤
逝去的感伤 2020-12-23 16:39

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

相关标签:
12条回答
  • 2020-12-23 17:02

    @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'
    
    0 讨论(0)
  • 2020-12-23 17:05

    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>
    
    0 讨论(0)
  • 2020-12-23 17:06

    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>
    
    0 讨论(0)
  • 2020-12-23 17:09

    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> -->
    
    0 讨论(0)
  • 2020-12-23 17:10

    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.

    0 讨论(0)
  • 2020-12-23 17:11

    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
    
    0 讨论(0)
提交回复
热议问题