Spring Boot没有创建数据源 [英] Spring boot did not create datasource

查看:190
本文介绍了Spring Boot没有创建数据源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我实际上有一个问题,就是Spring Boot不会初始化数据源 在这里您可以找到所有必要的信息:

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

Application.java

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

application.yaml

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

pom.xml代码段

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.

推荐答案

是的,我知道了.我只是忘了添加

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 :)

对不起我!

这篇关于Spring Boot没有创建数据源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆