Spring Boot DataSource Configuration Java Example

Spring Boot DataSource Configuration Java Example

Now a days (Date: May 2017) almost all application which use Spring framework using Spring Boot and to connect data base using java as configuration class please use example below:

First you will have define database config in your properties file or YML file. I will be using YML file to keep data base configuration as below:

  • Database.yml:

Java class to read data base configuration and return jdbctemplate:

  • JavaHonkDataSourceConfig.java:

Note: To run this application Database.yml should be in your class-path and to get JDBCTemplate object you can use annotation as usual below is sample:

@Autowired
@Qualifier(“jdbcJavahonk”)
private JdbcTemplate jdbcTemplate;

Reference: Spring boot data base configuration

Leave a Reply

Your email address will not be published. Required fields are marked *

I am not Robot *