conscience
conscience

Reputation: 487

Spring boot did not create datasource

I actually have the problem, that spring boot does not initialise a datasource here you could find all necessary information:

Application.java

@Configuration
@ComponentScan
@EnableAutoConfiguration
class Application {

    public static void main(final String[] args) {
        SpringApplication.run(Application.class, args);
    }
}

@Entity
class Device extends AbstractPersistable<Long> {
    private String name;

    Device() {
    }

    Device(String name) {

        this.name = name;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}

interface DeviceRepository extends JpaRepository<Device, Long> {}

@RestController
class DeviceController {

    @Autowired
    private DeviceRepository deviceRepository;

    @RequestMapping("/devices")
    Collection<Device> getAllDevices() {
        return deviceRepository.findAll();
    }
}

application.yaml

spring:
  datasource:
    url: jdbc:mysql://localhost:3306/test
    username: root
    password: mysql
    driverClassName: com.mysql.jdbc.Driver

pom.xml snippet

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

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

I'm trying to fix this issue for the last couple of hours and read almost every thread about this problem here on stack overflow, but I didn't get a solution till now.

Upvotes: 0

Views: 3598

Answers (1)

conscience
conscience

Reputation: 487

Yea ok I got it. I just forgot to add the

<dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
</dependency>

After adding this everything works just fine :)

Silly me!

Upvotes: 2

Related Questions