Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured

前端 未结 28 2527
天命终不由人
天命终不由人 2020-11-30 19:57

I am working on a Spring Boot Batch example with MongoDB and I have already started the mongod server.

When I launch my application, I

相关标签:
28条回答
  • 2020-11-30 20:55

    check your application.properties

    changing

    spring.datasource.driverClassName=com.mysql.jdbc.Driver
    

    to

    spring.datasource.driver-class-name=com.mysql.jdbc.Driver
    

    worked for me. Full config:

    spring.datasource.url=jdbc:mysql://localhost:3306/db
    spring.datasource.username=
    spring.datasource.password=   
    spring.datasource.driver-class-name=com.mysql.jdbc.Driver
    spring.jpa.database-platform = org.hibernate.dialect.MySQL5Dialect
    spring.jpa.generate-ddl=true
    spring.jpa.hibernate.ddl-auto = update
    
    0 讨论(0)
  • 2020-11-30 20:56

    Adding h2 dependency to the pom file can resolve such issues. ...... com.h2database h2 ......

    0 讨论(0)
  • 2020-11-30 20:57

    Not to the point of the question (can be related though), but, if you bootstrap a new project and wondering why do you get the same error, it may come from the artifactId of spring-boot-starter-data-jpa in the dependency section. I gave the dependency below. You will need to define the database to get rid of this.

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>
    
    0 讨论(0)
  • 2020-11-30 20:57

    It simply means you have downloaded a spring starter code with database dependency without configuring your database. So it doesn't know how to connect. For Spring boot version 2.18 do the below steps to fix it.

    1. Create a database for the driver you have downloaded ie mysql/mongo etc.
    2. In your applications.properties file add the db connection info. Sample is given for mysql if your db is mongo change it for mongo.

      spring.datasource.url=jdbc:mysql://localhost:3306/db_name_that_you_created spring.datasource.username=your_db_username_here spring.datasource.password=your_db_pass_here spring.datasource.driver-class-name=com.mysql.jdbc.Driver spring.jpa.database-platform = org.hibernate.dialect.MySQL5Dialect spring.jpa.generate-ddl=true spring.jpa.hibernate.ddl-auto = update

    3. Reboot the server it will be running.
    0 讨论(0)
提交回复
热议问题