Failed to bind properties under '' to com.zaxxer.hikari.HikariDataSource Spring Boot - spring

I am getting following error when I try to run spring boot application.
Description:
Failed to bind properties under '' to com.zaxxer.hikari.HikariDataSource:
Property: driverclassname
Value: oracle.jdbc.OracleDriver
Origin: "driverClassName" from property source "source"
Reason: Unable to set value for property driver-class-name
Action:
Update your application's configuration
This is same issue I have but i am not using maven.
I am using spring Boot 2.0.0 with following starters.
dependencies {
compile "org.springframework.boot:spring-boot-starter-web"
compile "org.mybatis.spring.boot:mybatis-spring-boot-starter:1.3.1"
testCompile "org.springframework.boot:spring-boot-starter-test"
}
And this is my application.properties file
spring.datasource.url= *****
spring.datasource.username= ******
spring.datasource.password= ******

Same problem with me (Spring boot 2),
I Fixed add driver-class.
Look up application.properties file.
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
Full code.
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5InnoDBDialect
spring.jpa.show-sql=true
spring.jpa.hibernate.ddl-auto=upate
spring.datasource.url=jdbc:mysql://localhost:3306/database_name
spring.datasource.username=admin
spring.datasource.password=admin1234

As Stephane Nicoll said, you don't have driver on your classpath. You need to include jdbc driver on your gradle build as below. However, you don't have to stick to driver version that I have included.
dependencies {
compile "org.springframework.boot:spring-boot-starter-web"
compile "org.mybatis.spring.boot:mybatis-spring-boot-starter:1.3.1"
testCompile "org.springframework.boot:spring-boot-starter-test"
runtime('com.oracle:ojdbc7:12.1.0.2.0')
}

I had the same error when updating from Spring Boot 2.0.6 to Spring Boot 2.1.6.
Explicitly setting driver class name spring.datasource.driver-class-name=com.mysql.jdbc.Driver in application.properties has resolved the issue

I have added the below in properties file
spring.datasource.driverclassname = com.mysql.jdbc.Driver
hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
and added the below in POM file
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
It is working fine now.

You have to add
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
dependency in your pom.xml file

The driver is not on your classpath, this is an interesting problem and I think the failure analyzer can be improved to avoid that misleading message. If that's your problem, please confirm and open an issue so that we try to improve it.

We have to add the dependency and have to remove property "spring.datasource.driver-class-name"
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>

In case anyone is running intelliJ this error isn't immediately clear it can be caused by a missing profile. Eg. missing vm args for -Dspring.profiles.active=local (or whatever your property file name might be)

You just need to add below in pom.xml
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>

If youre running intelliJ and run into this issue just add this dependency in your pom.xml file:
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>

This happened to me as well.
But after adding the correct MySQL version in my pom.xml, and explicitly adding the driver details to application.properties resolved the issue.
Application.properties
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
pom.xml
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.34</version>
</dependency>
Add the MySQL version to pom.xml as per the version installed.

Check your pom.xml if you dont have the mysql dependency, can add like this
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
Befor of update the file, run maven
mvn clean install
to update your maven's dependencies

I had the same error, the mistake was in pom.xml file. I had a mistake in my SQL connector dependency. If its okay in your case check also application.properties file you may not include driver
spring.datasource.url=jdbc:mysql://localhost:3307/test?useSSL=false
spring.datasource.username=root
spring.datasource.password=root
spring.jpa.show-sql=true
spring.jpa.generate-ddl=false
spring.jpa.hibernate.ddl-auto=update
spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true
spring.mvc.view.prefix = /WEB-INF/jsp/
spring.mvc.view.suffix = .jsp

All of these answers require code changes, and in my situation the code wasn't the problem. The error would occur randomly in my development environment, seamingly for no reason, not associated with any config or code change that I'd made.
I think I've found a consistent way to fix it, but I'm not sure why it works.
Shut down InteliJ IDEA
Delete ".idea" and "build" folders
Restart IDEA
This seems to resolve it, but the random nature of this really bothers me. I don't know why it occurs, or why the above fixes it.
I'm just adding this in case it helps others.

I only needed to re-import all gradle dependencies.

Add the maven dependency
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
Add or modify the application.properties file.
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5InnoDBDialect
Older version used:
spring.jpa.database-platform=org.hibernate.dialect.MySQL5InnoDBDialect
This does NOT work anymore; hence, the change to spring.jpa.properties.hibernate.dialect.
Resulting in the following:
spring.datasource.url=jdbc:mysql://localhost:3306/<db name>
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.username=<db username>
spring.datasource.password=<db password>
spring.jpa.hibernate.ddl-auto=validate
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5InnoDBDialect
spring.jpa.database=mysql
spring.jpa.show-sql=true
Clean the build artifacts from previous builds
mvn clean install
An for IntelliJ, invalidate the cache and restart.
File --> Invalidate Caches...
Run the project.

Related

package org.springframework.data.jpa does not exist using maven and IntelliJ

I have been having a problem with downloading a dependency for my spring boot project.
What have I tried:
I have tried adding this
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
to my pom.xml file. I have also tried looking up the dependency in IntelliJ to no avail. I need this so I can import org.springframework.data.jparepository to work thanks in advance.

Spring data jpa format_sql does not format query

I am working on a spring data jpa project and need some help formatting the sql statements which are being logged. Here are the properties I used and tried, some are working, others are ignored as indicated.
Also some other stuff I have tried
#works
spring.jpa.hibernate.ddl-auto=validate
#works
spring.jpa.show-sql=true
#ignored
spring.jpa.properties.hibernate.format_sql=true
spring.jpa.properties.hibernate_format_sql=true
spring.jpa.properties.format_sql=true
spring.jpa.hibernate.format_sql=true
spring.jpa.format_sql=true
#ignored
spring.jpa.properties.hibernate.type=trace
I found on several stackoverflow questions and other sites saying that " spring.jpa.properties.hibernate.format_sql=true " should work, but here it is ignored.
In the documentation in the list of properties it is not listed: https://docs.spring.io/spring-boot/docs/current/reference/html/application-properties.html#appendix.application-properties.data
According to https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#data.sql.jpa-and-spring-data.creating-and-dropping hibernate properties should be set with spring.jpa.properties.hibernate...
The project, does not have other hibernate configuration except the hibernate core dependency in pom.xml , which is needed . Here are the two relevant dependencies in pom:
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
</dependency>
spring data jpa is version 2.5.6 , hibernate 5.4.32
Is there anything I can do to be able to format the sql statements with spring.jpa properties ?
Thank you!
LE: I have debugged the code and saw that the entitymanager has the hibernate.format_sql=true property.

Active profile ignored

Sample code
I have already added "spring.profiles.active=local" in application.properties file
But while running the application it is not able to recognize the profile and running with default profile
application.properties
# Tomcat Server Config
server.port=8071
#Profile Config
spring.profiles.active=local
application-local.properties
# Spring JPA Config
spring.datasource.url=jdbc:postgresql://localhost:5432/User
spring.datasource.username=postgres
spring.datasource.password=amt123`
# Hibernate Config
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
spring.jpa.properties.hibernate.id.new_generator_mappings=false
spring.jpa.properties.hibernate.format_sql=true
spring.jpa.hibernate.ddl-auto=none
"spring.devtools.add-properties" default value is true
Once it is set to false, spring boot disables profile configuration.
For me even if I set the value to true, still profile configuration was not enabled
I fixed this issue by removing the dev-tool dependency and adding it again.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
</dependency>
I am not sure on the internal workflow.
If anyone has a proper explanation for this, please comment

h2database login screen not working in my spring application

I am using h2dabase as in memory database in my application.
I have added following dependency in my pom.xml file.
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
</dependency>
Following is my application.properties
spring.application.name=currency-exchange-service
server.port=8000
spring.jpa.show-sql=true
spring.h2.console.enabled=true
Following is the error I am getting on the browser:
To reproduce the error, I've downloaded a fresh Spring boot project with the spring-boot-starter-web and h2 modules. When using your settings, the URL was inaccessible just like your screenshot showed.
The URL did became accessible when I added
spring.h2.console.path=/h2-console to application.properties.

Postgresql driver not found for maven dependency

I am running a spring project with maven and I am trying to use postgresql. I've added the dependency to pom.xml, but at tomcat startup, I get the following error:
java.lang.ClassNotFoundException: org.postgresql.Driver
pom.xml dependency:
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>9.3-1101-jdbc41</version>
</dependency>
It appears that Maven isn't downloading the jar so the Driver class is not found. Any ideas?
What also worked for me if you are on intellj:
right klick pom.xml->Maven->Reimport
Don't know why it doesn't download the artifact on copy paste.
When I put this in my pom, the artifact gets downloaded. Maybe you should clean your maven repository cache or delete the folders manually and retry.
If you came here for "missing artifact" error, This worked for me:
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>9.4.1212</version>
</dependency>
For PostgreSQL 10 I use this:
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.1.4</version>
</dependency>
Maven wasn't recognizing the new dependency I have added to pom.xml, so I added it through 'Dependency view' from the xml and that did the trick. Thank you for your answers.
Try to rebuild the artifact, most likely only the added dependency was not included there
You need to place a copy of the jar in the tomcat/lib folder.

Resources