P
P
ProtCN2020-10-17 19:09:42
MySQL
ProtCN, 2020-10-17 19:09:42

How to initialize a database in Spring JPA based on data from a read file?

During the launch of my application, I have such important data as url, username, password for connecting to the database (DataSource) read from some configuration file.

I don't know how to initialize a Bean DataSource with this data if it has nothing to do with JavaConfig.

I have javaconfig

@Configuration
public class JavaConfig {
    
    @Bean
    public DataSource dataSource() {
        return new MysqlDataSource();
    } 
   
    /* etc code */
}


I have a method for reading url, username, password data from a third-party resource (configured by me for security), which I want to immediately use in my DataSource, but I don’t know how.
It should look something like this:
public class SQLBase {

    public static void initDataSource() {
        /* reading data */
        ??.setUrl(url);
        ??.setUsername(username);
        ??.setPassword(password);
    }
}


I'm sorry, I don't understand something and I need your help.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question