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

Time:07-05

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

CodePudding user response:

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

CodePudding user response:

You can use System.getProperty method or can create a Pojo like below -

System.getProperty("spring.datasource.url")

or

 @Component
 @ConfigurationProperties(prefix = "spring.datasource")
 public class AppConfig {
    public String url;
    public String password;
 }

or

@Value("${spring.datasource.url}")
public String dbUrl;
  • Related