SpringBoot提供了很好的DataSource自动配置功能,在这里我们只需要引入有关的依赖(可以通过start.spring.io配置,也可以手动在pom.xml配置), 这里引入了jdbc的依赖,还有springBoot自带的h2数据库
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
同样,对启动类xxLearnSpringApplication进行简单的改造:
@SpringBootApplication
@Slf4j
public class XiaoLearnSpringApplication