PostgreSQL
 sql >> Base de Dados >  >> RDS >> PostgreSQL

Springboot postgres Falha ao determinar uma classe de driver adequada


O problema é resolvido criando dois beans. Um bean separado é criado para DataSource e NamedParameterJdbcTemplate.
    @Bean
    public DataSource dataSource(){
        System.out.println(driverClass+" "+ url+" "+username+" "+password);
        DriverManagerDataSource source = new DriverManagerDataSource();
        source.setDriverClassName(driverClass);
        source.setUrl(url);
        source.setUsername(username);
        source.setPassword(password);
        return source;
    }

    @Bean
    public NamedParameterJdbcTemplate namedParameterJdbcTemplate(){
        NamedParameterJdbcTemplate namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(this.dataSource());
        return namedParameterJdbcTemplate;
    }