[英]How to find "spring.datasource.url=" for application.properties?
I am a beginner at developing.我是开发的初学者。
How to get"spring.datasource.url=" for application.properties?如何获取 application.properties 的“spring.datasource.url=”?
enter image description here在此处输入图像描述
application.properties应用程序.properties
spring.datasource.url=jdbc:mysql://localhost:3306/sms?useSSL=fals&serverTimezone=UTC&useLegacyDatetimecode=false
spring.datasource.username=root
spring.datasource.password=123123
#Hibernate
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5InnoDBDialect
#Hibernate auto ddl
spring.jpa.hibernate.ddl-auto=update
logging.level.org.hibernate.SQL=DEBUG
My Database enter image description here我的数据库在此处输入图像描述
Inject dataSourceProperties
, and use determineUrl
:注入
dataSourceProperties
,并使用determineUrl
:
import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties;
...
@Autowired
DataSourceProperties dataSourceProperties;
You can then call:然后你可以打电话:
String dbUrl = dataSourceProperties.determineUrl();
you can used Properties:你可以使用属性:
package java.util.Properties包 java.util.Properties
Properties springProperties = new Properties();
springProperties.getProperty("spring.datasource.url");
learn more => https://www.javatpoint.com/properties-class-in-java了解更多 => https://www.javatpoint.com/properties-class-in-java
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.