2
votes

I want to create a basic Spring started application and make a get request. I have added Spring JPA, Spring Web dependencies and started running in port 8080, but my application to start. It says " Description:

Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured. Reason: Failed to determine a suitable driver class ".

I have not added any database dependency cause I don't require it, Is that mandatory to have database dependency in my project? Here is my pom.xml

<?xml version="1.0" encoding="UTF-8"?>

4.0.0 org.springframework.boot spring-boot-starter-parent 2.3.1.RELEASE com.example java-sample-project 0.0.1-SNAPSHOT java-sample-project Demo project for Spring Boot

<properties>
    <java.version>1.8</java.version>
</properties>

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

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-devtools</artifactId>
        <scope>runtime</scope>
        <optional>true</optional>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
        <exclusions>
            <exclusion>
                <groupId>org.junit.vintage</groupId>
                <artifactId>junit-vintage-engine</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>
3
You are including JPA. How are you going to use JPA without a dtabase?M. Deinum

3 Answers

1
votes

If you include Spring JPA, then yes, it's mandatory.

But you can easily disable the Spring autoconfigration:

spring.autoconfigure.exclude=
  org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration, \
  org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration, \
org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration
1
votes

You might be having the data dependency in your POM: (or build.gradle)

<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-data-jpa</artifactId>
  <version>2.3.1.RELEASE</version>
</dependency>

If so, please remove that.

1
votes

Yes it is mandatory. But if you don't want to have a real database running, then use the in-memory database H2. Just add com.h2database:h2 to the dependencies.