Spring Boot Application not configuring datasource through CircleCi - mysql

I have a Spring Boot Rest Api (v2.2.6.RELEASE) with a mysql database
When I ssh into the remote box and run java -jar it builds and runs perfectly but when I run that same command through CircleCi I get the following.
2021-12-25 17:53:30.112 ERROR 30084 --- [ main] 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
Below is an extract of the properties file:
spring.jpa.hibernate.ddl-auto=update
spring.datasource.url=****
spring.datasource.username=*****
spring.datasource.password=*****
spring.datasource.initialization-mode=always
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5InnoDBDialect
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
Also, Im using the same user for both CircleCi and when I ssh and deploy manually.
Any help and guidance would be appreciated.

Related

Spring boot JPA error in gradle build from docker

I have a Gradle project, i added jpa to it with:
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-data-jpa', version: '2.4.3'
implementation group: 'mysql', name: 'mysql-connector-java', version: '8.0.23'
And in application.properties i have added the following lines:
spring.datasource.url=jdbc:mysql://user:pass#localhost/dbname
spring.datasource.username=null
spring.datasource.password=null
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
### Hibernate Properties
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5InnoDBDialect
spring.jpa.hibernate.ddl-auto = update
It's working fine when the mysql server is hosted on the machine. But when i am building my spring boot application inside the docker with ./gradlew build command, without hosting the mysql its giving me the exception:
oreApplicationTests > contextLoads() FAILED
java.lang.IllegalStateException at DefaultCacheAwareContextLoaderDelegate.java:132
Caused by: org.springframework.beans.factory.BeanCreationException at AbstractAutowireCapableBeanFactory.java:1796
Caused by: javax.persistence.PersistenceException at AbstractEntityManagerFactoryBean.java:403
Caused by: org.hibernate.exception.JDBCConnectionException at SQLStateConversionDelegate.java:112
Caused by: com.mysql.cj.jdbc.exceptions.CommunicationsException at SQLError.java:174
Caused by: com.mysql.cj.exceptions.CJCommunicationsException at NativeConstructorAccessorImpl.java:-2
Caused by: java.net.UnknownHostException at InetAddress.java:797
I don't want these errors during the build, I only want to turn on the mysql server when i will be using the jars. So i don't want these errors during the compile time.
I ran into a similar error when using MySQL. The solution for me was to add in the dialect to the .properties folder. I figured out the error was coming from JPA not knowing which dialect to use based on the database.
spring.jpa.database-platform=org.hibernate.dialect.{your dialect here}
Also keep in mind tests want to run with an in memory database by default so you need to wire up your tests to run as expected.

Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured with Spring, MySql and Gradle

I am working with Spring Boot and MySql. When I launch the application, I get the following error:
***************************
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).
application.properties
spring.datasource.url=jdbc:mysql://localhost:3306/*****
spring.datasource.username=username
spring.datasource.password=password
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
build.gradle
dependencies {
classpath "org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}"
classpath "mysql:mysql-connector-java:$sqlClientVersion"
}
dependencies {
implementation 'mysql:mysql-connector-java:8.0.20'
}
Any help would be really appreciated

Springboot + JSP + Spring Security: Failed to configure a DataSource

I'm new using springboot and I've been triying to configure a project with it and spring security, but unfortunately I'm not able to run it. I'm getting the next error :
nested exception is org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Failed to determine a suitable driver class
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
I've been looking for a solution but I can't find anything that fit in my project.
Please, any idea?
You can see the project here :
Proyect
Thanks
In application.properties, Change
app.datasource.jdbc-url
app.datasource.username
app.datasource.password
app.datasource.driver-class-name
To
spring.datasource.url
spring.datasource.username
spring.datasource.password
spring.datasource.driver-class-name

Grails: ClassNotFoundException: com.mysql.jdbc.Driver in WAR deployment

This is an issue that just started happening recently and its only with specific projects and WAR deployment. I am not able to deploy a WAR file because I get the following exception
ERROR org.apache.tomcat.jdbc.pool.ConnectionPool - Unable to create initial connections of pool.
java.sql.SQLException: com.mysql.jdbc.Driver
at org.apache.tomcat.jdbc.pool.PooledConnection.connectUsingDriver(PooledConnection.java:254)
at org.apache.tomcat.jdbc.pool.PooledConnection.connect(PooledConnection.java:182)
at org.apache.tomcat.jdbc.pool.ConnectionPool.createConnection(ConnectionPool.java:712)
[.....]
Caused by: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:348)
at org.apache.tomcat.jdbc.pool.PooledConnection.connectUsingDriver(PooledConnection.java:246)
Nothing in my project has changed since my last successful deploy (I verify with git) and I can run the project fine using Spring Boot.
The mysql-connector is in my gradle build
runtime 'mysql:mysql-connector-java:5.1.46' (I have also tried changing to compile)
I have the driver declared properly in my application.yml
dataSource:
pooled: true
jmxExport: true
driverClassName: com.mysql.jdbc.Driver
dialect: org.hibernate.dialect.MySQL5InnoDBDialect
username: ****
password: ****
environments:
production:
dataSource:
password: *****
dbCreate: none
url: jdbc:mysql://localhost:3306/myapp
I am using Intellij IDE and can confirm that the mysql-connector is listed in my classpath and when I explode my WAR file mysql-connector-java-5.1.46.jar is listed in my WEB-INF/lib
I have done multiple cleans and rebuilds of the project. I am really at a loss for what is happening and as mentioned its only specific projects. I have other grails projects with identical config setups and deploy just fine but a handful of others give me this error. Any ideas?
Tomcat: 7.0.70
Java: 1.8.0_91
MySQL: 5.6 and 5.7 (fails on both)
Grails: 3.3.1
Update:
So if I put my mysql jar in my Tomcat lib folder instead of my project lib folder then it works. So that proves that the JAR file is valid. When I put the JAR file back into the WEB-INF/lib folder of my app then it doesn't work. So it seems for some reason the JAR file is being ignored or not loaded when its packaged with my app. Again though, its just some apps. I have other apps that works just fine with the lib packaged with the app.
I'm sure. It's not issue of jar file.
You can check here in repo and here for all versions of MySQL connectors
Please verify your dependency runtime "mysql:mysql-connector-java:5.1.46"
Verify your system MySQL server user and password and dataSource username , password.
Verify your MySQL running fine with valid credentials.
Because ERROR org.apache.tomcat.jdbc.pool.ConnectionPool - Unable to create initial connections of pool. this error will come when MySQL is not running on system or invalid username password.
One more possibility of error:
If you have updated your MySQL version. It will try to connect securely.
So by you need to pass some parameters to URL mysql://localhost:3306/yourDb?autoReconnect=true&useSSL=false&useUnicode=true
Last option if you are not resolved problem:
Update your dependency and configuration with latest version.
Dependency for your reference:
runtime "mysql:mysql-connector-java:6.0.6"
and Application.yml
dataSource:
dbCreate: update
pooled: true
url: jdbc:mysql://localhost:3306/YourDb?autoReconnect=true&useSSL=false&useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC
driverClassName: com.mysql.cj.jdbc.Driver
dialect: org.hibernate.dialect.MySQL5InnoDBDialect
username: yourUsername
password: yourPassword
properties:
...
driverClassName have been changed in latest version.
Hope this will helps you.

Hibernate Reverse Engineering with Eclipse and MySql

I'm having the hardest time getting Eclipse to connect and reverse engineer from a MySQL5 database. I can see Eclipse connecting to my MySQL database and can even see the tables through the "Data Source Explorer" view but when I try it after creating Hibernate Console and Configuration files, I get the error:
org.hibernate.console.HibernateConsoleRuntimeException:
Problems while loading database
driverclass (com.mysql.jdbc.Driver)
Problems while loading database
driverclass (com.mysql.jdbc.Driver)
java.lang.ClassNotFoundException:com.mysql.jdbc.Driver
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
From my simple java project, I start by creating a Hibernate Configuration File (cfg.xml).
Name of file: hibernate.cfg.xml
Session Factory name: org.hibernate.SessionFactory
Database Dialect: org.hibernate.dialect.MySQL5Dialect
Driver Class: com.mysql.jdbc.Driver
Connection Url: jdbc:mysql://localhost:3306/<myDatabaseName>
Default Schema: <myDatabaseName>
Username: correct username
Password: correct password
I also have selected the option to "Create a console Configuration"
At this point, I can see the new configuration listed in my "Hibernate Configuration" perspective/workbench pane. If I try to expand it, I get the earlier listed error.
I don't understand why I can see the database through the 'Data Source Explorer" and even though I'm using the DB connection profile listed in there as part of my configuration, I still get this error.
I also tried to create a new database profile using a manual mysql connector jar (mysql-connector-java-5.1.13-bin.jar) and same end result.
Versions of what I have:
Eclipse version: 3.6.0 aka Helios, Build 20100617 - 1415
MySQL: 5.1.34
Hibernate Tools (from JBoss): HibernateTools-3.3.1.v201006011046R-H111-GA
(placed into Eclipse's 'dropins' folder)
What am I doing wrong in my hibernate configuration setup?
Help!
Your Hibernate Console Configuration doesn't have the MySQL JDBC driver on its classpath, hence the java.lang.ClassNotFoundException:com.mysql.jdbc.Driver. From the reference guide of the Hibernate Tools:
3.4. Creating a Hibernate Console Configuration
...
alt text http://docs.jboss.org/tools/2.1.0.Beta1/hibernatetools/html_single/images/plugins/plugins_3.png
...
Classpath: The classpath for loading POJO and JDBC drivers; only needed if
the default classpath of the Project
does not contain the required classes.
Do not add Hibernate core libraries or
dependencies, they are already
included. If you get ClassNotFound
errors then check this list for
possible missing or redundant
directories/jars.
Include default classpath from project: When enabled the project
classpath will be appended to the
classpath specified above
Does the "associated project" have the MySQL JDBC driver declared as library? If not, then you must add it (either as a project library or in the above tab).