question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Datasource Autoconfiguration with spring.datasource properties breaks in 1.5.6.RELEASE whereas it works fine with 1.5.4.RELEASE version

See original GitHub issue

Unable to create datasource in the recent spring boot 1.5.6.RELEASE using spring.datasource properties whereas the same configuration works with 1.5.4.RELEASE.

Please find the configurations below:

application.yml

spring:
  datasource:
    driver-class-name: com.mysql.jdbc.Driver
    url: jdbc:mysql://localhost:3306/jpadb?autoReconnect=true&useSSL=false
    username: root
    password: root
  jpa:
    show-sql: true
    hibernate:
      ddl-auto: create-drop

pom.xml :

	<parent>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-parent</artifactId>
		<version>1.5.6.RELEASE</version>
		<relativePath/> 
	</parent>

	<properties>
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
		<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
		<java.version>1.8</java.version>
	</properties>

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

		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-devtools</artifactId>
			<scope>runtime</scope>
		</dependency>
		<dependency>
			<groupId>mysql</groupId>
			<artifactId>mysql-connector-java</artifactId>
			<scope>runtime</scope>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-test</artifactId>
			<scope>test</scope>
		</dependency>
	</dependencies>

Error :

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.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
naaraayanacommented, Feb 10, 2018

It seems that the dependency for datasource, spring-boot-starter-jdbc is not included

0reactions
le-van-tuancommented, Sep 5, 2018

In my way, there is two options to solve this issue :

  1. Manual config by create Data-source bean in your app :
@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;
}
  1. Upgrade your spring boot version : 1.5.4.RELEASE to 1.5.9.RELEASE

Hope it useful ✌️

Read more comments on GitHub >

github_iconTop Results From Across the Web

Spring Boot Reference Guide
Spring Boot auto-configuration attempts to automatically configure your Spring application based on the jar dependencies that you have added. For example, If ...
Read more >
Spring Boot + Spring data JPA + PostgreSQL - Mkyong.com
Puts a postgresql driver and defined the data source url in application.properties . Done, Spring Boot is able to connect to a PostgreSQL ......
Read more >
Tutorial: Build Microservices Using Spring Boot an - DZone
This step-by-step guide helps full-stack developers build components in microservices using Spring Boot and employ them in Docker.
Read more >
Spring Boot changelog - Awesome Java - LibHunt
We'd like to thank all the contributors who worked on this release! ... a configuration property for the driverClassName of the Liquibase DataSource...
Read more >
chore(deps): update all dependencies (major) (!151 ... - GitLab
org.springframework.boot:spring-boot-starter-batch (source), 2.3.2.RELEASE -> 3.0.0 · age, adoption, passing, confidence.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found