0

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

tricks. com
  • 45
  • 1
  • 6
  • Does this answer your question? [How to access a value defined in the application.properties file in Spring Boot](https://stackoverflow.com/questions/30528255/how-to-access-a-value-defined-in-the-application-properties-file-in-spring-boot) – AddeusExMachina Jul 04 '22 at 21:11

2 Answers2

1

Inject dataSourceProperties, and use determineUrl:

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

...


@Autowired
DataSourceProperties dataSourceProperties;

You can then call:

String dbUrl = dataSourceProperties.determineUrl();
Sébastien Le Callonnec
  • 26,254
  • 8
  • 67
  • 80
-1

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

Omar Hussien
  • 313
  • 1
  • 9