Spring Boot auto configuration for datasource

后端 未结 2 1989
春和景丽
春和景丽 2020-12-09 15:13

I try to create Spring Boot app with Hibernate 5 and Postgres 9. Now I have next error:

Parameter 0 of constructor in org.springframework.boot.autoconfigure         


        
相关标签:
2条回答
  • 2020-12-09 15:42

    well the above solution might worked but in my case with weblogic 11g above solution could not help me. so attaching this solution so anyone elsestruggling with this problem find it useful.

    solution:

    Adding DataSource bean configuration in component scan classpath will fix this for servlets 2.5 like weblogic 10.3.6(11g) like below

    @Configuration
    public class DBConfig{
    
           @Bean
           public DataSource dataSource(){
              DriverManagerDataSource dataSource = new DriverManagerDataSource();
              dataSource.setDriverClassName("oracle.jdbc.driver.OracleDriver");
              dataSource.setUrl("your url");
              dataSource.setUsername( "username" );
              dataSource.setPassword( "password" );
              return dataSource;
           }
    
    }
    
    0 讨论(0)
  • 2020-12-09 15:58

    You're missing several classes (mostly pool related) on your classpath. The easiest solution is to use the Spring boot starter for JPA, which is:

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>
    

    If you do this, you can remove the following dependencies since they're all part of the starter:

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
        <version>${spring.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-tx</artifactId>
        <version>${spring.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-orm</artifactId>
        <version>${spring.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.data</groupId>
        <artifactId>spring-data-jpa</artifactId>
        <version>${spring.data.version}</version>
    </dependency>
    
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-core</artifactId>
        <version>${hibernate.version}</version>
    </dependency>
    

    The alternative solution is to manually add a pool provider to your classpath, the default of spring-boot-starter-data-jpa is tomcat-jdbc (Hikari for Spring boot 2.x) but you can use any connection pool provider you want that is listed in the documentation.

    0 讨论(0)
提交回复
热议问题