Q:

JdbcTemplate throws an exception

I am trying to create JdbcTemplate bean as following:
@Configuration
public class ServiceBeanConfiguration {

    @Bean
    public JdbcTemplate jdbcTemplate() {
    DriverManagerDataSource driverManagerDataSource = new DriverManagerDataSource();
    driverManagerDataSource.setDriverClassName("org.postgresql.Driver");
    driverManagerDataSource.setUrl("jdbc:postgresql://localhost:5432/sp");
    driverManagerDataSource.setUsername("posthres");
    driverManagerDataSource.setPassword("password");

    DataSource dataSource = driverManagerDataSource;

    JdbcTemplate jdbcTemplate = new JdbcTemplate();
    jdbcTemplate.setDataSource(dataSource);
    return jdbcTemplate;
}

I autowire this @Bean into my service class. But as a result I receive error:
**************************
APPLICATION FAILED TO START
***************************

Description:

Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.

Reason: Failed to determine a suitable driver class

Action:

Consider the following:
    If you want an embedded database (H2, HSQL or Derby), please put it on the classpath.
    If you have database settings to be loaded from a particular profile you may need to activate it (no profiles are currently active).

A:

Create an application.properties and put spring.datasource properties in there. 
spring.datasource.url=jdbc:postgresql://localhost:5432/sp
spring.datasource.username=postgres
spring.datasource.password=password

Remove your ServiceBeanConfiguration and restart your application. 
Spring Boot will automatically configure the DataSource and JdbcTemplate for you. 

