[英]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 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 snippet pom.xml片段
<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 :) 添加这一切后一切正常:)
Silly me! 傻我!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.