简体   繁体   中英

Spring Boot DataSource Configuration

I was reading baeldungs article on configuring datasource programmatically. There is a particular comment which confused me. Can someone please explain with an example what the author meant here. Thanks in advance.

在此处输入图像描述

It is in context of Externalization not Datasource specifc. In which you put your application related parameters outside the code files using.properties, .xml or.yml config files. It allows you to configure your application without compiling. If you want to change, you just have to change the values in config file and application will behave as per provided values no need to recompile. We normally externalized properties for Datasource, Connection Pool, Logging configuration, Endpoints and many more.

For example in case of Datasource configuration you can pass DB url, username, password in external configuration file instead of code and refer those values through keys. So in future if the datasource url changes you just have to make change in config file. Otherwise you would have to make changes in code which would need recompile and rebuild your application for changes to be effective.

But also take into consideration of sensitivity of values too for which there are some techniques which i believe outside the scope of this question.

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