0

I am trying to connect Spring Boot back-end to PostgreSQL but get this error

***************************
APPLICATION FAILED TO START
***************************
Description:

Parameter 0 of constructor in 
org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration 
required a bean of type 'javax.sql.DataSource' that could not be found.
- Bean method 'dataSource' not loaded because @ConditionalOnProperty 
(spring.datasource.jndi-name) did not find property 'jndi-name'
- Bean method 'dataSource' not loaded because @ConditionalOnBean (types: 
org.springframework.boot.jta.XADataSourceWrapper; SearchStrategy: all) did 
not find any beans


Action:

Consider revisiting the conditions above or defining a bean of type 
'javax.sql.DataSource' in your configuration.

I have been struggling with this error for 2 days till this moment

I have these dependencies in my pom.xml

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

    <dependency>
        <groupId>org.postgresql</groupId>
        <artifactId>postgresql</artifactId>
        <version>9.4-1206-jdbc42</version>
    </dependency>

and this is my application.yml

spring:
 jpa:
  database: POSTGRESQL
  show-sql: true
  hibernate:
    ddl-auto: create-drop
 datasource:
  platform: postgres
  url: jdbc:postgresql://localhost:5432/H4E
  username: postgres
  password: 123456

I am using PostgreSQL 10 with pgAdmin 3 LTS

8
  • Try adding a connection pool like Apache DBCP2 as a dependency in your POM, I think it should already come with one in the dependencies of the JPA starter but maybe they changed that. Commented Feb 28, 2018 at 18:34
  • whats your springboot version? Commented Feb 28, 2018 at 18:50
  • looks like issue with with your package strcture. Can you please share package tree diagram? Commented Feb 28, 2018 at 18:52
  • change postgresql JDBC driver version. Try to use 42.2.1 instead of 9.4-1206-jdbc42. Commented Feb 28, 2018 at 18:56
  • also (just in case) append quotes to your DB connection string url: "jdbc:postgresql://localhost:5432/H4E" Commented Feb 28, 2018 at 19:03

1 Answer 1

2

Add driverClassName property under the spring.datasource. You should get something like this

spring:
    jpa:
        database: POSTGRESQL
        show-sql: true
        hibernate:
            ddl-auto: create-drop
    datasource:
        platform: postgres
        url: "jdbc:postgresql://localhost:5432/H4E"
        username: postgres
        password: 123456
        driverClassName: org.postgresql.Driver
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.