Spring Cloud Data Flow Kubernetes Deployment fails for external database - Cannot load driver class: com.mysql.cj.jdbc.Driver - mysql

I am following the developer guide to deploy SCDF to a minikube cluster on my local machine. Used the helm chart approach. Was able to get it working with the defaults. The default deploys a mariadb in the cluster. I wanted to change it to use an external mysql db that is running in a docker container in my machine (outside the cluster). Followed the recommendations to change the values.yaml to enable the external DB and attributes for external DB connection (URI, dbname, user/pwd etc.).
Then deployed using "helm install my-release -f values.yaml bitnami/spring-cloud-dataflow"
The SCDF pod (& skipper pod) errors out because it can't find the mysql jdbc driver. kubectl logs on the pods show the following error: "java.lang.IllegalStateException: Cannot load driver class: com.mysql.cj.jdbc.Driver"
How do I include the mysql jdbc driver in the image for SCDF that gets deployed (or resolve this problem). I read SCDF already includes the drivers for std databases (true ?). New to helm/k8s so apologies if solution is obvious... Other posts on similar error all talk about including this in the pom.xml . But this is not a dependency issue with my (task) app but SCDF itself.
thanks
-------------------- more detail on the exception stack ---------------
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.zaxxer.hikari.HikariDataSource]: Factory method 'dataSource' threw exception; nested exception is java.lang.IllegalStateException: Cannot load driver class: com.mysql.cj.jdbc.Driver
at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:657)
...

Looks like I just need to specify the mariadb jdbc driver in the values.yaml file for mysql as well. That got past the load class error.
But still would like to know how to prevent class load error for a different driver specified when SCDF is deployed to k8s via the helm chart.

Related

How to connect to JBoss EAP 7.3 using VisualVM in OpenShift

I am trying to connect an application with VisualVM, but VisualVM unable to connect with application: Below is the env:
JBoss EAP 7.3
Java 11
OpenShift
I have tried to configure it in different ways, but all failed:
Config try 1:
Use few env variables in script file, so that it could execute first (file contents are mentioned below):
echo *** Adding system property for VisulVM ***
batch
/system-property=jboss.modules.system.pkgs:add(value="org.jboss.byteman,com.manageengine,org.jboss.logmanager")
/system-property=java.util.logging.manager:add(value="org.jboss.logmanager.LogManager")
run-batch
I can see that above commands executed successfully and above properties are available in JBoss config (I verified using Jboss cli command).
JAVA_TOOLS_OPTIONS: -agentlib:jdwp=transport=dt_socket,server=y,address=8000,suspend=n -Dcom.sun.management.jmxremote=true -Dcom.sun.management.jmxremote.port=3000 -Dcom.sun.management.jmxremote.rmi.port=3001 -Djava.rmi.server.hostname=127.0.0.1 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Xbootclasspath/a:/opt/eap/modules/system/layers/base/org/jboss/log4j/logmanager/main/log4j-jboss-logmanager-1.2.0.Final-redhat-00001.jar -Xbootclasspath/a:/opt/eap/modules/system/layers/base/org/jboss/logmanager/main/jboss-logmanager-2.1.14.Final-redhat-00001.jar
Result:
- java.lang.RuntimeException: WFLYCTL0079: Failed initializing module org.jboss.as.logging
- Caused by: java.util.concurrent.ExecutionException: java.lang.IllegalStateException: WFLYLOG0078: The logging subsystem requires the log manager to be org.jboss.logmanager.LogManager. The subsystem has not be initialized and cannot be used. To use JBoss Log Manager you must add the system property "java.util.logging.manager" and set it to "org.jboss.logmanager.LogManager"
Config 2:
JAVA_TOOL_OPTIONS= -agentlib:jdwp=transport=dt_socket,server=y,address=8000,suspend=n -Dcom.sun.management.jmxremote=true -Dcom.sun.management.jmxremote.port=3000 -Dcom.sun.management.jmxremote.rmi.port=3001 -Djava.rmi.server.hostname=127.0.0.1 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Djava.util.logging.manager=org.jboss.logmanager.LogManager -Djboss.modules.system.pkgs=org.jboss.byteman,org.jboss.logmanager -Xbootclasspath/a:/opt/eap/modules/system/layers/base/org/jboss/log4j/logmanager/main/log4j-jboss-logmanager-1.2.0.Final-redhat-00001.jar -Xbootclasspath/a:/opt/eap/modules/system/layers/base/org/jboss/logmanager/main/jboss-logmanager-2.1.14.Final-redhat-00001.jar
Result:
WARNING: Failed to instantiate LoggerFinder provider; Using default.
java.lang.IllegalStateException: The LogManager was not properly installed (you must set the "java.util.logging.manager" system property to "org.jboss.logmanager.LogManager")
Config 3:
• Modify in standalone.conf, where I put all required configuration in this file.
Result:
WARNING: Failed to instantiate LoggerFinder provider; Using default.
java.lang.IllegalStateException: The LogManager was not properly installed (you must set the "java.util.logging.manager" system property to "org.jboss.logmanager.LogManager")
Kindly suggest that what is the correct configurations?

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

JBPM: Add MySQL connector dependency to kie workbench [ver 6.2]

I'm trying to add mysql connector dependency to kie workbench. I added it by uploading the jar to the artifact repository and adding the dependency by going to project settings. When the service task that uses the connector executes, it's not able to load the mysql's Driver class. Here's more detail on how I'm using the service task - Service task using Hibernate
When the service task execute I get this message on the workbench - Unexpected error encountered : [com.sample.bpmn.hello:36 - GetData:3] -- Unable to build entity manager factory
When I look at wildfly's server.log, it seems the jar didn't get added properly - java.lang.ClassNotFoundException: Could not load requested class : com.mysql.jdbc.Driver
When I add the dependency on the workbench, I see the following warnings. I'm not able to figure out what they mean -
Verification of class com.mysql.jdbc.integration.c3p0.MysqlConnectionTester failed and will not be available for authoring. Please check the necessary external dependencies for this project are configured correctly.
Verification of class com.mysql.jdbc.integration.jboss.ExtendedMysqlExceptionSorter failed and will not be available for authoring. Please check the necessary external dependencies for this project are configured correctly.
Verification of class com.mysql.jdbc.integration.jboss.MysqlValidConnectionChecker failed and will not be available for authoring. Please check the necessary external dependencies for this project are configured correctly.
Please let me know if more info is needed.
Much appreciated.
[PS] - I must say that I just got started with hibernate as well with no prior experience. So it could be a basic thing I'm missing there.

class not found com.mysql.jdbc.Driver jdbc when trying to connect to a Mysql Database

I'm developing a web application in java where I'm trying to connect to a MySQL database using JDBC template ( with springs dao) but I always get:
SEVERE: Servlet.service() for servlet [dispatcher] in context with path [/DealingOfInsiders] threw exception [Request processing failed;
nested exception is org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot load JDBC driver class 'com.mysql.jdbc.Driver '] with root cause
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
[....]
I think the problem is coming from the file mysql-connector-java-5.1.25-bin.jar which contains the targeted class ...
So I tried many things to get this problem solve :
I've configured the build path of my project whith this jar but it didn't worked
I ve also put the file in the folder : WEB-INF/lib , didn't worked
I ve configured a classpath variable to this jar in eclipse ( preference ->java->buildpath->classpath variabe ) it didn't worked
I have put the jar file in the tomcat library but it didn't work as well
'com.mysql.jdbc.Driver '
^^ // remove this space
There appears to be a trailing space on the name?
'com.mysql.jdbc.Driver '
Apart from that, "com.mysql.jdbc.Driver" is correct.
The WEB-INF/lib folder is a good place for project-specific drivers & libraries; keeping the Tomcat shared folders up-to-date is not so easy.
Back in JDBC days you had to load the class with Class.forName( clazzName) to register it before you asked JDBC for a connection, but that's not the issue here.
I had this issue but with the Postgres driver and I'm using Eclipse. If you're using Tomcat 7, try adding the JAR file to the lib folder in your Tomcat directory. That worked for me. I didn't have to use Class.forName() or put the JAR in my classpath. I hope this 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).