Spring 引导连接到 MySQL 远程数据库

Spring Boot connection to MySQL remote database

我正在 Spring Boot 中开发应用程序。我正在使用 phpMyAdmin(它在我的大学是免费的)数据库来保持持久性。我的数据库在远程服务器上。如何为远程数据库连接配置数据源?

请帮助我在 属性 文件和数据源 bean 配置中使用我的配置 class 中的注释进行配置。

例如:登录用户名:admin,密码:root

可能喜欢

在文件中 application.properties

spring.datasource.url=jdbc:mysql://lamp.ii.us.edu.pl:3306/ii309808
spring.datasource.username=admin
spring.datasource.password=root
spring.datasource.driver-class-name=com.mysql.jdbc.Driver

(3306是MySQL数据库管理系统的默认端口号,如果无法通过3306端口连接,请咨询您的系统管理员)

参考:https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-sql.html#boot-features-connect-to-production-database