java 如何查找www.example.com的“spring.datasource.url =”application.properties?

uinbv5nw  于 2023-01-29  发布在  Java
关注(0)|答案(2)|浏览(142)

我是一个初学者在发展。

如何获取www.example.com的“spring.datasource.url =”application.properties?

enter image description here

应用程序.属性

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

我的数据库enter image description here

8hhllhi2

8hhllhi21#

进样dataSourceProperties,并使用determineUrl

import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties;

...

@Autowired
DataSourceProperties dataSourceProperties;

您可以拨打:

String dbUrl = dataSourceProperties.determineUrl();
xqkwcwgp

xqkwcwgp2#

您可以使用属性:
包java.util.Properties

Properties springProperties = new Properties();
springProperties.getProperty("spring.datasource.url");

了解更多信息=〉https://www.javatpoint.com/properties-class-in-java

相关问题