Spring how to set data source in Spring Download

I am just learning Spring, and the last couple of days I have been struggling on how to configure Spring JdbcTemplate to use my PostgreSQL database. I do not know how to do that. I keep reading the documentation (e.g. http://docs.spring.io/spring/docs/current/spring-framework-reference/html/jdbc.html ), but it seems like I'm going in a circle.

From the errors created, it seems that he cannot create an instance of the RelationalDatabase class, which I wrote as a bean. I'm not sure what it takes to instantiate the class properly.

How to move from something like guides (e.g. https://spring.io/guides/gs/relational-data-access/ ) that fully work on a more complex solution?

Relational Database Class

@Repository
public class RelationalDatabase 
{

    private JdbcTemplate jdbcTemplate;

    public RelationalDatabase(){}


    public RelationalDatabase(JdbcTemplate jdbcTemplate)
    {
        this.jdbcTemplate = jdbcTemplate;
    }

    @Autowired
    public void setDataSource(javax.sql.DataSource dataSource) {
        this.jdbcTemplate = new JdbcTemplate(dataSource);
    }

    public JdbcTemplate getJdbcTemplate() {
        return jdbcTemplate;
    }


    public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
        this.jdbcTemplate = jdbcTemplate;
    }

}

\ SRC \ main \ resources \ application-dev.properties

spring.datasource.url=jdbc:postgresql://192.168.56.102:5432/scibase
spring.datasource.type=org.postgresql.ds.PGPoolingDataSource 
spring.datasource.username=lemon
spring.datasource.password=XXXXXX
spring.datasource.platform=postgres
spring.datasource.max-active=100
spring.datasource.name=lime
spring.database.driverClassName=org.postgresql.Drive

Stack trace (summary)

org.springframework.beans.factory.BeanCreationException: error creating a bean named "relational database": injection self-timer dependencies failed; nested exception org.springframework.beans.factory.BeanCreationException: autowire method failed: public void com.scientifi.papers.db.relational.RelationalDatabase.setDataSource (javax.sql.DataSource);

Org.springframework.beans.factory.BeanCreationException nested exception: an error creating a bean with the name 'dataSource' defined in the class path resource [Org / springframework / downloads / Autoconfiguration / JDBC / DataSourceAutoConfiguration $ NonEmbeddedConfiguration.class]: bean failed to execute instance factory;

org.springframework.beans.BeanInstantiationException: instantiate [javax.sql.DataSource]: factory 'dataSource' ; org.springframework.boot.autoconfigure.jdbc.DataSourceProperties $DataSourceBeanCreationException: . , . , ( "dev" ).

!

+4
2

"r" ? ( NONE)

spring.database.driverClassName=org.postgresql.Driver

spring.database.driverClassName=org.postgresql.Drive
+3

, Spring Junit.

@SpringApplicationConfiguration (classes = Application.class) Junit Test. Spring Boot

0

Source: https://habr.com/ru/post/1626106/


All Articles