October 2017
Intermediate to advanced
396 pages
10h 2m
English
If you want to create an object of the JdbcTemplate class to access data in your Spring application, you need to remember that it requires a DataSource to create the database connection. Let's create a template once, and reuse it. Do not create one for each thread, it is thread-safe after construction:
JdbcTemplate template = new JdbcTemplate(dataSource);
Let's configure a JdbcTemplate bean in Spring with the following @Bean method:
@Bean
public JdbcTemplate jdbcTemplate(DataSource dataSource) {
return new JdbcTemplate(dataSource);
}
In the preceding code, we use the constructor injection to inject the DataSource with the JdbcTemplate bean in the Spring application. The dataSource bean being referenced ...
Read now
Unlock full access