在Spring Boot中,可以通过application.properties或application.yml文件来配置数据源。以下是两个示例:
1. application.properties配置文件示例:
# 数据源配置
spring.datasource.url=jdbc:mysql://localhost:3306/demo
spring.datasource.username=root
spring.datasource.password=123456
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
2. application.yml配置文件示例:
# 数据源配置
spring:
datasource:
url: jdbc:mysql://localhost:3306/demo
username: root
password: 123456
driver-class-name: com.mysql.jdbc.Driver
以上示例中,配置了一个名为"demo"的MySQL数据源,其中包括URL、用户名、密码和驱动类。根据实际情况,你需要将这些配置修改为你自己的数据库信息。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
相关推荐:springboot数据源如何配置