Spring Error LoggingFailureAnalysisReporter after Initialize new project - java

i made a new project with Spring Initializr and run it after import in the Intellij without any change in the code that generated by the IDE and i get the following error :
restartedMain] o.s.b.d.LoggingFailureAnalysisReporter
***************************
APPLICATION FAILED TO START
***************************
Description:
Failed to configure a DataSource: 'url' attribute is not specified and no embedded
datasource could be configured.
Reason: Failed to determine a suitable driver class
Action:
Consider the following:
If you want an embedded database (H2, HSQL or Derby), please put it on the classpath.
If you have database settings to be loaded from a particular profile you may need to
activate it (no profiles are currently active).
Process finished with exit code 0
my pom.xml is:
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.2.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>demo</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</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>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
MariaDB version: 10.3.23
Spring Ver: 2.3.2
Java Ver: openjdk 1.8.0_252

This Error comes from bad database configuration of the application.properties under the: /src/main/resources
read the: this github repo for knowing all the setting that you can and should use in the application.properties but for your simple project use the below instruction:
add this lines of code to the application.properties:
# ===============================
# = DATA SOURCE
# ===============================
# Set here configurations for the database connection
# Connection url for the database "netgloo_blog"
spring.datasource.url = jdbc:mysql://localhost:3306/netgloo_blog?useSSL=false
# Username and password
spring.datasource.username = root
spring.datasource.password = root
# Keep the connection alive if idle for a long time (needed in production)
spring.datasource.testWhileIdle = true
spring.datasource.validationQuery = SELECT 1
# ===============================
# = JPA / HIBERNATE
# ===============================
# Use spring.jpa.properties.* for Hibernate native properties (the prefix is
# stripped before adding them to the entity manager).
# Show or not log for each sql query
spring.jpa.show-sql = true
# Hibernate ddl auto (create, create-drop, update): with "update" the database
# schema will be automatically updated accordingly to java entities found in
# the project
spring.jpa.hibernate.ddl-auto = update
# Naming strategy
spring.jpa.hibernate.naming-strategy = org.hibernate.cfg.ImprovedNamingStrategy
# Allows Hibernate to generate SQL optimized for a particular DBMS
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect
this basic configuration will get you out of trouble but remember to change the username and password for your MySQL or MariaDB Database.
you can use this topic for more information about change User and Pass for Database in spring and jhipster projects

Related

No session repository could be auto-configured(session store type is 'redis')

I am following the spring security tutorial from this link on that tutorial third part. I have to use redis to hand away session information to resource backend.
Here my applicaiton.yml file:
server:
port: 9000
security:
sessions: NEVER
spring:
session:
store-type: redis
redis:
host: localhost
port: 6379
logging:
level:
org.springframework:
security: DEBUG
session: TRACE
Also, I use HeaderHttpSessionStrategy bean as a session strategy
#Bean
HeaderHttpSessionStrategy sessionStrategy() {
return new HeaderHttpSessionStrategy();
}
My pom couldn't find the related class declaration and give me
package org.springframework.session.web.http does not exist
Above error Here my pom.xml file.
<properties>
<java.version>14</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
I am new in spring and spring-security world. Can any advice solve this problem?
Edit:
After I added the new dependency in pom
<dependency>
<groupId>org.springframework.session</groupId>
<artifactId>spring-session</artifactId>
<version>1.3.5.RELEASE</version>
</dependency>
I solve the above problem but this time hit me the new one it says:
No session repository could be auto-configured, check your configuration (session store type is 'redis'
My redis configuration on application.yml is above. And I am using redis on docker. My docker yml is:
redis:
image: redis
ports:
- "6379:6379"
I got this error recently. I was using Spring Boot 2.4.0. I had added the dependency for Spring Session, but forgot to add one for Jedis.
<dependency>
<groupId>org.springframework.session</groupId>
<artifactId>spring-session-data-redis</artifactId>
</dependency>
When I first deployed, with that it gave me the message:
No session repository could be auto-configured, check your configuration (session store type is 'redis')
After I added this dependency and rebuilt my JAR, everything worked.
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
</dependency>
Perhaps that will help someone else.

Failed to bind properties under " to com.zaxxer.hikari.HikariDataSource:" Springboot

I have already added ojdbc ddriver and included the dependency in pom, but I still get the error mentioned in the title. Please help.
Earlier I ran the application with a local postgres db. Now trying to connect to a remote oracle db, and encountered this problem. I am logged into the necessary firewalls.
The appplication started and performed as exected with the postgresdb.
I get the following logs when trying to start my application now -
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2020-03-06 12:08:51.786 ERROR 27236 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :
***************************
APPLICATION FAILED TO START
***************************
Description:
Failed to bind properties under '' to com.zaxxer.hikari.HikariDataSource:
Property: driverclassname
Value: oracle.jdbc.OracleDriver
Origin: "driverClassName" from property source "source"
Reason: Failed to load driver class oracle.jdbc.OracleDriver in either of HikariConfig class loader or Thread context classloader
Action:
Update your application's configuration
Process finished with exit code 1
The pom file is as below
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.2.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>package</groupId>
<artifactId>QualityScore</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>QualityScore</name>
<description>Demo project in Spring Boot</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc8</artifactId>
<version>12.2.0.1</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Application.properties -
##Postgres settings
##spring.datasource.url=jdbc:postgresql:*****
##spring.datasource.username=*****
##spring.datasource.password=*****
##spring.jpa.database-platform = org.hibernate.dialect.PostgreSQLDialect
spring.jpa.hibernate.ddl-auto = none
spring.jpa.hibernate.show-sql=true
# Oracle settings
spring.datasource.url=jdbc:oracle:*****
spring.datasource.username=*****
spring.datasource.password=*****
spring.datasource.driver-class=oracle.jdbc.driver.OracleDriver
# HikariCP settings
spring.datasource.hikari.connection-timeout=60000
spring.datasource.hikari.maximum-pool-size=5
#spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true
I got the solution or fix.
I added the following property in application.properties
spring.datasource.driver-class=oracle.jdbc.driver.OracleDriver
and explicitly specified the driver(ojdbc8) in the modules of the project structure.
Now it works!!! Thank you everyone for your help!!
you application.properties is wrong. You have:
#spring.datasource.url=jdbc:*****
#spring.datasource.username=****
#spring.tasource.password=*****
#spring.jpa.database-platform = *****
spring.jpa.hibernate.ddl-auto = none
spring.jpa.hibernate.show-sql=true
spring.datasource.url=jdbc:oracle:****
spring.datasource.username=*****
spring.datasource.password=*****
#spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true
Recipientlist=*****
but you don't have your driver-class-name set. should be:
#spring.datasource.url=jdbc:*****
#spring.datasource.username=****
#spring.tasource.password=*****
#spring.jpa.database-platform = *****
spring.jpa.hibernate.ddl-auto = none
spring.jpa.hibernate.show-sql=true
spring.datasource.url=jdbc:oracle:****
spring.datasource.username=*****
spring.datasource.password=*****
spring.datasource.driver-class-name=oracle.jdbc.OracleDriver
#spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true
Recipientlist=*****
Regards!
In my controller test classes, this error occurred when running the tests. Even with the spring.datasource.driver-class-name property set.
To resolve this, we added the DataSouce attribute with the #MockBean annotation in the controller test classes:
#MockBean
private DataSource dataSource;
The test classes performed perfectly.

Unable to connect to MySQL using Java Spring

Guys for 3 days I am searching for an answer and can't find the exact answer for my problem. So I am doing some tutorials on Spring and Hibernate and get stuck when trying to establish a connection between Spring Boot project, MySQL database and Tomcat server. Here is my "pom.xml" file:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.bookstore</groupId>
<artifactId>bookstore</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Bookstore</name>
<description>frontend part for our bookstore project</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.3.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</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-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
And here are my properties:
spring.thymeleaf.cache=false
# ===============================
# = DATA SOURCE
# ===============================
# Set here configurations for the database connection
spring.datasource.url=jdbc:mysql://localhost:3306/bookstoredatabase?autoReconnect=true&useSSL=false
# Username and secret
spring.datasource.username=root
spring.datasource.password=target
# Keep the connection alive if idle for a long time (needed in production)
spring.datasource.testWhileIdle = true
spring.datasource.validationQuery = SELECT 1
# ===============================
# = JPA / HIBERNATE
# ===============================
# Use spring.jpa.properties.* for Hibernate native properties (the prefix is
# stripped before adding them to the entity manager).
# Show or not log for each sql query
spring.jpa.show-sql=true
# Hibernate ddl auto (create, create-drop, update): with "update" the database
# schema will be automatically updated accordingly to java entities found in
# the project
spring.jpa.hibernate.ddl-auto = update
# Allows Hibernate to generate SQL optimized for a particular DBMS
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect
I am using Tomcat from XAMPP - version 7.0.56. MySQL Server and the connector are both version 8. Without using Tomcat, I am perfectly able to connect to any database, edit it, etc.
Here are the errors, which occur:
INFO 15816 --- [main] org.hibernate.Version: HHH000412: Hibernate Core {5.0.11.Final}
INFO 15816 --- [main] org.hibernate.cfg.Environment: HHH000206: hibernate.properties not found
INFO 15816 --- [main] org.hibernate.cfg.Environment: HHH000021: Bytecode provider name:javassist
INFO 15816 --- [main] o.hibernate.annotations.common.Version: HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
ERROR 15816 --- [main] o.a.tomcat.jdbc.pool.ConnectionPool: Unable to create initial connections of pool. com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server. Attempted reconnect 3 times. Giving up.
The full error log can be seen here . I have tried so many things. Please help me guys.
EDIT:
Okay. I have read the error log more carefully. I am using Tomcat from XAMPP, version 7.056, but Spring starts Tomcat with version 8. I don't know if I should make another question, but when I added <tomcat.version>7.0.56</tomcat.version> to my properties, the error log changed into this
I'm sorry. I checked Trace now.
When you check the bug report, was probably fixed in connector/J 5.1.41.
change this to your pom.xml
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.15</version>
</dependency>
Have you created database called bookstoredatabase on mysql?
and I think you should add dependency of mysql connector to pom.xml
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>

How to fix "Driver does not support get/set network timeout for connections" while connecting to oracle database from spring boot app?

I was trying to connect to my table and insert some data.We are using oracle database.
In the code I have used oracle thin driver ojdbc14.I am getting
2018-12-27 11:08:58.810 INFO 16548 --- [ main] com.zaxxer.hikari.pool.PoolBase : HikariPool-1 - Driver does not support get/set network timeout for connections. (oracle.jdbc.driver.T4CConnection.getNetworkTimeout()I)
2018-12-27 11:08:58.810 ERROR 16548 --- [ main] com.zaxxer.hikari.pool.PoolBase : HikariPool-1 - Failed to execute isValid() for connection, configure connection test query (oracle.jdbc.driver.T4CConnection.isValid(I)Z).
I am fairly new to spring boot and was actually trying to
do
this demo -
https://www.devglan.com/spring-jdbc/working-with-springboot-jdbctemplate
only changes I have done is in my pom.xml and application.properties.
Is there any thing else needed for oracle? How i should solve this?All the example I see for oracle in net is with hibernate.Is is necessary to include hibernate approach?
Thank you in advance.
pom.xml
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.1.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<dependencies>
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc14</artifactId>
<version>10.2.0.4.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<!-- <dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency> -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- HikariCP connection pool -->
<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
<version>3.2.0</version>
</dependency>
</dependencies>
application.properties
spring.datasource.url=jdbc:oracle:thin:#//url/service
spring.datasource.username=user
spring.datasource.password=password
spring.datasource.driver-class-name=oracle.jdbc.driver.OracleDriver
That is because you are using a very old version of ojdbc.
You should be using the latest versions of the Oracle JDBC driver to connect to your Oracle database.
From a quick test here:
the warning is still present with version 11.2.0.1
there is no warning with version 12.1.0.2
oracle.jdbc.driver.T4CConnection.getNetworkTimeout API is in Oracle JDBC 12.1.0.2(https://docs.oracle.com/database/121/JAJDB/toc.htm).
but oracle.jdbc.driver.T4CConnection.getNetworkTimeout API is not in Oracle JDBC 11.2.0.1(https://download.oracle.com/otn_hosted_doc/jdeveloper/905/jdbc-javadoc/oracle/jdbc/OracleConnectionWrapper.html)

Failed to load driver class com.mysql.jdbc.Driver

I am trying to run my Spring Boot backend with two profiles, one using H2 in memory database and the second one using MySQL. H2 database works just fine, but when I switch to MySQL I get
APPLICATION FAILED TO START
***************************
Description:
Failed to bind properties under '' to com.zaxxer.hikari.HikariDataSource:
Property: driverclassname
Value: com.mysql.jdbc.Driver;
Origin: "driverClassName" from property source "source"
Reason: Failed to load driver class com.mysql.jdbc.Driver; in either of HikariConfig class loader or Thread context classloader
Action:
Update your application's configuration
I have tried deleting .m2, reimporting, maven clean, compile, install and most of the things I could find on the internet, no success. The funny thing is that I have other project with MySQL database only, I had similar issue, but adding mysql-connector-java dependency solved it. I have no clue right now.
application.properties
spring.profiles.active=#profilename#
#H2 in memory database
domain.datasource.type=H2
domain.datasource.url=jdbc:h2:mem:store;MODE=MYSQL;
domain.datasource.driver-class=org.h2.Driver
domain.datasource.username=sa
domain.datasource.password=
domain.datasource.generate-dll=true
application-local_mysql.properties
spring.profiles.active=#profilename#
#MySQL local database
domain.datasource.type=MYSQL
domain.datasource.url=jdbc:mysql://localhost:3600/store;
domain.datasource.driver-class=com.mysql.jdbc.Driver;
domain.datasource.username=store
domain.datasource.password=store
domain.datasource.generate-dll=false
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>sk.personal</groupId>
<artifactId>my-project</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>my-project</name>
<description>My personal project.</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.5.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</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</artifactId>
<version>2.0.5.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
</dependencies>
<profiles>
<profile>
<id>local_h2</id>
<properties>
<profilename>local_h2</profilename>
</properties>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile>
<profile>
<id>local_mysql</id>
<properties>
<profilename>local_mysql</profilename>
<maven.test.skip>true</maven.test.skip>
</properties>
</profile>
</profiles>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
DatasourceConfig.java
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.jdbc.DataSourceBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType;
import javax.sql.DataSource;
#Configuration
public class DatasourceConfig {
#Value("${domain.datasource.url}")
private String url;
#Value("${domain.datasource.username}")
private String username;
#Value("${domain.datasource.password}")
private String password;
#Value("${domain.datasource.type}")
private String type;
#Value("${domain.datasource.driver-class}")
private String driverClass;
#Bean
public DataSource dataSource() {
if (type.equals("MYSQL")) {
return DataSourceBuilder
.create()
.username(username)
.password(password)
.url(url)
.driverClassName(driverClass)
.build();
} else {
EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder();
return builder
.setType(EmbeddedDatabaseType.H2)
.build();
}
}
}
In my case the next dependency was missing:
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
In case of using IntelliJ and if you inherit from a <parent>, you can view your effective pom.xml by right clicking anywhere inside your pom.xml, then:
and search for the mysql-connector-java artifact as mentioned.
The answer is so embarrassing. I appended the driver line of application.properties with a semicolon ...
Obviously, it did't recognize that driver.
I had a problem where I was using Spring Boot 2.2.0.RELEASE and needed to connect to an old Mysql DB (5.1.73), which required me to downgrade to mysql-connector-java version 5.1.38
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.38</version>
</dependency>
Since Spring boot was expecting a newer mysql-java-connector, which has been renamed to com.mysql.cj.jdbc.Driver, I also had to add the spring datasource driver-class-name setting in my spring boot db config.
So my spring boot config ended up like this:
spring:
datasource:
url: 'localhost'
password: password
username: user
driver-class-name: com.mysql.jdbc.Driver
just add mysql and jdbc dependencies like below
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jdbc</artifactId>
</dependency>
You don't specify version of MYSQL JDBC driver, so you're likely getting version 8.x, where the driver is named differently than in previous versions:
com.mysql.cj.jdbc.Driver
In my case error throws:
Property: driverclassname
Value: com.mysql.cj.jdbc.Driver
Origin: "driverClassName" from property source "source"
Reason: Failed to load driver class com.mysql.cj.jdbc.Driver in either of HikariConfig class loader or Thread context classloader
So I have just added mysql dependency:
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
Try upgrading your driver. Coz Mysql community has updated class name from com.mysql.jdbc.Driver to com.mysql.cj.jdbc. Check More Details
Change the database driver dependency scope to 'runtime'
For example:
<dependency>
<groupId>com.{yourDatabaseGroupid}</groupId>
<artifactId>{yourDatabaseArtifactId}</artifactId>
<scope>runtime</scope>
</dependency>
You should add: spring.datasource.driver-class-name=com.mysql.jdbc.Driver to your application.properties file .
My **application.properties : **
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5InnoDBDialect
spring.datasource.url=jdbc:mysql://localhost:3306/db_name?useSSL=false&useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC&zeroDateTimeBehavior=convertToNull
spring.datasource.username=root
I cant believe it!
In intellij: Build->rebuild project solved the issue for me!
For more information:
pom.xml:
application.properties:
this issue for me was also caused by the version of mysql.
all i had to do is add the version of mysql in pom.xml dependencies
(in my case the verion is 8.0.25)
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.25</version>
</dependency>
make sure to reload the maven dependecies before your run
I had the same problem as you. For me, it was because of having h2 database dependency!
I don't know how these two can affect each other, but all I did was removing this dependency and now it works just fine!
I my case all configurations were correct but I still get this error.
In Intellij, go in the project structure (ctrl + alt + maj + S) in windows.
Look if u get some problems.
If yes, go on maven in the sidebar: clic on "Generate sources and Update Folders for All projetct"
That resolve my error !
Had to specify the jar path inside project->Properties->JPA-> connection Profile -> JAR List
I had the same issue and the root cause was [ spring.profile.active ]
and the fix is [ spring.profiles.active ] where it is profiles plural
and it was my mistake.
go to https://start.spring.io
In that site:
Dependencies > Search for Mysql drver > select it > Click explore button > copy the latest version of mysql connector > add it into your application.properties file

Categories

Resources