Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

URL must start with 'jdbc' in sprinboot

My application was running but when, I got application error. I tried several times the same thing happening. I checked database connection and everything is fine. These are my logs

Exception


Caused by: java.lang.IllegalArgumentException: URL must start with 'jdbc'
at org.springframework.util.Assert.isTrue(Assert.java:116) ~[spring-core-5.0.5.RELEASE.jar:5.0.5.RELEASE]
at org.springframework.boot.jdbc.DatabaseDriver.fromJdbcUrl(DatabaseDriver.java:268) ~[spring-boot-2.0.1.RELEASE.jar:2.0.1.RELEASE]
at org.springframework.boot.autoconfigure.jdbc.DataSourceProperties.determineDriverClassName(DataSourceProperties.java:230) ~[spring-boot-autoconfigure-2.0.1.RELEASE.jar:2.0.1.RELEASE]
at org.springframework.boot.autoconfigure.jdbc.DataSourceProperties.initializeDataSourceBuilder(DataSourceProperties.java:176) ~[spring-boot-autoconfigure-2.0.1.RELEASE.jar:2.0.1.RELEASE]
at org.springframework.boot.autoconfigure.jdbc.DataSourceConfiguration.createDataSource(DataSourceConfiguration.java:43) ~[spring-boot-autoconfigure-2.0.1.RELEASE.jar:2.0.1.RELEASE]
at org.springframework.boot.autoconfigure.jdbc.DataSourceConfiguration$Hikari.dataSource(DataSourceConfiguration.java:81) ~[spring-boot-autoconfigure-2.0.1.RELEASE.jar:2.0.1.RELEASE]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_161]
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_161]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_161]
at java.lang.reflect.Method.invoke(Unknown Source) ~[na:1.8.0_161]
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154) ~[spring-beans-5.0.5.RELEASE.jar:5.0.5.RELEASE]
... 40 common frames omitted

application.properties


#======================
# DATA SOURCE
#=====================

spring.datasource.url="jdbc:mysql://localhost:3306/customerdb?useSSL=false"
spring.datasource.username=root
spring.datasource.password=root
#spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.dbcp2.test-while-idle=true
spring.datasource.dbcp2.validation-query= SELECT 1


#============================
# JPA/Hibernate
#===========================
spring.jpa.show-sql=true
spring.jpa.hibernate.ddl-auto=create-drop
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
spring.jpa.hibernate.naming.physical-strategy=org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy

#===================================================================
# Spring Security / Queries for AuthenticationManagerBuilder
#===================================================================
spring.queries.users-query=select email,password active form user where email=?
spring.queries.roles-query=select u.email, r.role from user u inner join user_role ur on(u.user_id=ur.user_id) inner join role r on(ur.role_id=r.role_id) where u.email=?

# ===============================
# Thymeleaf configurations
# ===============================
spring.thymeleaf.mode=LEGACYHTML5
spring.thymeleaf.cache=false

#====================================
#LOGGING
#====================================
logging.level.root=warn
logging.level.org.org.springframework.web=debug
logging.level.org.org.Hibernate=error
like image 925
Ng Sharma Avatar asked Apr 12 '18 13:04

Ng Sharma


People also ask

Is it mandatory to provide JDBC driver details in spring boot?

Yes it is mandatory. But if you don't want to have a real database running, then use the in-memory database H2. Just add com. h2database:h2 to the dependencies.

What is Spring Boot starter jdbc?

Spring Boot JDBC provides starter and libraries for connecting an application with JDBC. In Spring Boot JDBC, the database related beans such as DataSource, JdbcTemplate, and NamedParameterJdbcTemplate auto-configures and created during the startup. We can autowire these classes if we want to use it.

What does JDBC in the URL mean?

A JDBC URL provides a way of identifying a database so that the appropriate driver recognizes it and connects to it. In the Derby documents, a JDBC URL is referred to as a database connection URL.

How does spring boot application connect to database using JDBC?

To access the Relational Database by using JdbcTemplate in Spring Boot application, we need to add the Spring Boot Starter JDBC dependency in our build configuration file. Then, if you @Autowired the JdbcTemplate class, Spring Boot automatically connects the Database and sets the Datasource for the JdbcTemplate object.


1 Answers

replace this :

spring.datasource.url="jdbc:mysql://localhost:3306/customerdb?useSSL=false"

with this :

spring.datasource.url=jdbc:mysql://localhost:3306/customerdb?useSSL=false
like image 59
Elarbi Mohamed Aymen Avatar answered Oct 26 '22 23:10

Elarbi Mohamed Aymen