简体   繁体   中英

How to find "spring.datasource.url=" for application.properties?

I am a beginner at developing.

How to get"spring.datasource.url=" for application.properties?

enter image description here

application.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 :

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

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

learn more => https://www.javatpoint.com/properties-class-in-java

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM