Vert.x JDBC client: Could not load the required implementation - java

I'm trying to connect to a database with the vert.x JDBC client:
import io.vertx.core.AbstractVerticle;
import io.vertx.core.*;
import io.vertx.jdbcclient.JDBCConnectOptions;
import io.vertx.jdbcclient.JDBCPool;
import io.vertx.sqlclient.*;
public class MainVerticle extends AbstractVerticle {
#Override
public void start(Promise<Void> startPromise) throws Exception {
JDBCPool pool = JDBCPool.pool(
vertx,
new JDBCConnectOptions()
.setJdbcUrl("jdbc:sqlserver://some_ip")
.setUser("user")
.setPassword("password"),
new PoolOptions().setMaxSize(16)
);
pool
.query("SELECT * FROM test")
.execute()
.onFailure(e -> {
System.out.println(e.toString());
})
}
}
This gives me the result:
java.sql.SQLException: Could not load the required implementation
I assume, that this is caused by line 53 here.
However, I don't really understand what the code there is doing.
Complete stacktrace:
java.sql.SQLException: Could not load the required implementation
at io.agroal.api.AgroalDataSource.from(AgroalDataSource.java:53)
at io.agroal.api.AgroalDataSource.from(AgroalDataSource.java:33)
at io.vertx.jdbcclient.impl.AgroalCPDataSourceProvider.getDataSource(AgroalCPDataSourceProvider.java:73)
at io.vertx.ext.jdbc.impl.JDBCClientImpl.createDataSource(JDBCClientImpl.java:274)
at io.vertx.ext.jdbc.impl.JDBCClientImpl.lambda$getDataSourceHolder$6(JDBCClientImpl.java:256)
at io.vertx.core.impl.ContextImpl.lambda$null$0(ContextImpl.java:160)
at io.vertx.core.impl.AbstractContext.dispatch(AbstractContext.java:96)
at io.vertx.core.impl.ContextImpl.lambda$executeBlocking$1(ContextImpl.java:158)
at io.vertx.core.impl.TaskQueue.run(TaskQueue.java:76)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:630)
at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
at java.base/java.lang.Thread.run(Thread.java:831)
Caused by: java.lang.ClassNotFoundException: io.agroal.pool.DataSource
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:636)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:182)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:519)
at io.agroal.api.AgroalDataSource.from(AgroalDataSource.java:49)
... 12 more

The error can be resolved by adding
implementation group: 'io.agroal', name: 'agroal-pool', version: '1.0'
to the build.gradle.

Related

Exclude config classes from spring context

I have a class that configures Cassandra database:
#Configuration
#EnableCassandraRepositories(basePackages = { BASE_PACKAGE })
public class CassandraConfig {
#Value("${spring.data.cassandra.contact-points}")
private String contactPoints;
#Value("${spring.data.cassandra.keyspace-name}")
private String keyspaceName;
#Value("${spring.data.cassandra.datacenter-name}")
private String datacenterName;
#Value("${spring.data.cassandra.port}")
private int port;
#Bean
public CqlSessionFactoryBean session() {
CqlSessionFactoryBean session = new CqlSessionFactoryBean();
session.setContactPoints(contactPoints);
session.setKeyspaceName(keyspaceName);
session.setLocalDatacenter(datacenterName);
session.setPort(port);
return session;
}
...
}
And I have an empty test that just loads spring context
#SpringBootTest
class ApplicationTest {
#Test
void contextLoads() {
}
}
When I run it, I see this exception message:
Failed to load ApplicationContext
java.lang.IllegalStateException: Failed to load ApplicationContext
...
Caused by: com.datastax.oss.driver.api.core.AllNodesFailedException: Could not reach any contact point, make sure you've provided valid addresses (showing first 1 nodes, use getAllErrors() for more): Node(endPoint=127.0.0.1/<unresolved>:9042, hostId=null, hashCode=29caef8c): [com.datastax.oss.driver.api.core.connection.ConnectionInitException: [s0|control|connecting...] Protocol initialization request, step 1 (OPTIONS): failed to send request (io.netty.channel.StacklessClosedChannelException)]
at app//com.datastax.oss.driver.api.core.AllNodesFailedException.copy(AllNodesFailedException.java:141)
at app//com.datastax.oss.driver.internal.core.util.concurrent.CompletableFutures.getUninterruptibly(CompletableFutures.java:149)
at app//com.datastax.oss.driver.api.core.session.SessionBuilder.build(SessionBuilder.java:835)
at app//org.springframework.data.cassandra.config.CqlSessionFactoryBean.buildSystemSession(CqlSessionFactoryBean.java:498)
at app//org.springframework.data.cassandra.config.CqlSessionFactoryBean.afterPropertiesSet(CqlSessionFactoryBean.java:451)
at app//org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1863)
at app//org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1800)
... 166 more
Suppressed: com.datastax.oss.driver.api.core.connection.ConnectionInitException: [s0|control|connecting...] Protocol initialization request, step 1 (OPTIONS): failed to send request (io.netty.channel.StacklessClosedChannelException)
at app//com.datastax.oss.driver.internal.core.channel.ProtocolInitHandler$InitRequest.fail(ProtocolInitHandler.java:356)
at app//com.datastax.oss.driver.internal.core.channel.ChannelHandlerRequest.writeListener(ChannelHandlerRequest.java:87)
at app//io.netty.util.concurrent.DefaultPromise.notifyListener0(DefaultPromise.java:578)
at app//io.netty.util.concurrent.DefaultPromise.notifyListenersNow(DefaultPromise.java:552)
at app//io.netty.util.concurrent.DefaultPromise.notifyListeners(DefaultPromise.java:491)
at app//io.netty.util.concurrent.DefaultPromise.addListener(DefaultPromise.java:184)
at app//io.netty.channel.DefaultChannelPromise.addListener(DefaultChannelPromise.java:95)
at app//io.netty.channel.DefaultChannelPromise.addListener(DefaultChannelPromise.java:30)
at app//com.datastax.oss.driver.internal.core.channel.ChannelHandlerRequest.send(ChannelHandlerRequest.java:76)
at app//com.datastax.oss.driver.internal.core.channel.ProtocolInitHandler$InitRequest.send(ProtocolInitHandler.java:193)
at app//com.datastax.oss.driver.internal.core.channel.ProtocolInitHandler.onRealConnect(ProtocolInitHandler.java:124)
at app//com.datastax.oss.driver.internal.core.channel.ConnectInitHandler.lambda$connect$0(ConnectInitHandler.java:57)
at app//io.netty.util.concurrent.DefaultPromise.notifyListener0(DefaultPromise.java:578)
at app//io.netty.util.concurrent.DefaultPromise.notifyListeners0(DefaultPromise.java:571)
at app//io.netty.util.concurrent.DefaultPromise.notifyListenersNow(DefaultPromise.java:550)
at app//io.netty.util.concurrent.DefaultPromise.notifyListeners(DefaultPromise.java:491)
at app//io.netty.util.concurrent.DefaultPromise.setValue0(DefaultPromise.java:616)
at app//io.netty.util.concurrent.DefaultPromise.setFailure0(DefaultPromise.java:609)
at app//io.netty.util.concurrent.DefaultPromise.tryFailure(DefaultPromise.java:117)
at app//io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe.fulfillConnectPromise(AbstractNioChannel.java:321)
at app//io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe.finishConnect(AbstractNioChannel.java:337)
at app//io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:707)
at app//io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:655)
at app//io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:581)
at app//io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:493)
at app//io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:986)
at app//io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
at app//io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
at java.base#17.0.1/java.lang.Thread.run(Thread.java:833)
Suppressed: io.netty.channel.AbstractChannel$AnnotatedConnectException: Connection refused: /127.0.0.1:9042
Caused by: java.net.ConnectException: Connection refused
at java.base/sun.nio.ch.Net.pollConnect(Native Method)
at java.base/sun.nio.ch.Net.pollConnectNow(Net.java:672)
at java.base/sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:946)
at io.netty.channel.socket.nio.NioSocketChannel.doFinishConnect(NioSocketChannel.java:330)
at io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe.finishConnect(AbstractNioChannel.java:334)
at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:707)
at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:655)
at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:581)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:493)
at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:986)
at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
at java.base/java.lang.Thread.run(Thread.java:833)
Caused by: io.netty.channel.StacklessClosedChannelException
at io.netty.channel.AbstractChannel$AbstractUnsafe.flush0()(Unknown Source)
As I understand, it tries to connect to the database but it cannot, thus, it fails.
I tried different ways to exclude this class from context loading like #EnableAutoConfiguration(exclude = CassandraConfig.class) but then it fails with
java.lang.IllegalStateException: The following classes could not be excluded because they are not auto-configuration classes: com.myproject.test.config.CassandraConfig
Is there some advices or best practices how to solve this problem?
The error you're getting makes sense, CassandraConfig is not an autoconfiguration but a configuration class.
To exclude it you could use a Spring profile:
#Configuration
#Profile("!test")
public class CassandraConfig {
Then in your test class:
#SpringBootTest(properties = "spring.profiles.active=test")
class ApplicationTest {

java.lang.reflect.InvocationTargetException error javafx even though there is no code [duplicate]

This question already has answers here:
Exception in Application constructor when using JavaFX
(2 answers)
Closed 1 year ago.
I am new to javafx so I decided to do a project,
But when I run the program (literally no code inside the start method)
It does not work it says java.lang.reflect.InvocationTargetException error and one more
here is the code
package com.front.fire;
import javafx.application.Application;
import javafx.stage.Stage;
class FrontFireMain extends Application{
#Override
public void start(Stage arg0) throws Exception {
}
}
Exception in thread "main" java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:78)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:567)
at java.base/sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:1071)
Caused by: java.lang.RuntimeException: Unable to construct Application instance: class com.front.fire.FrontFireMain
at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:890)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:195)
at java.base/java.lang.Thread.run(Thread.java:831)
Caused by: java.lang.NoSuchMethodException: com.front.fire.FrontFireMain.<init>()
at java.base/java.lang.Class.getConstructor0(Class.java:3517)
at java.base/java.lang.Class.getConstructor(Class.java:2238)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$8(LauncherImpl.java:801)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:474)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:447)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:391)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:446)
at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:174)
... 1 more
Your main class extends javafx.application.Application needs to be public. Change your class as below.
package com.front.fire;
import javafx.application.Application;
import javafx.stage.Stage;
public class FrontFireMain extends Application{
#Override
public void start(Stage arg0) throws Exception {
}
}

Exception in thread "main" java.lang.NoClassDefFoundError: javafx/application/Application

I'm trying to execute a .jar file which I produced from a JavaFX project (i already set the VM Options in Intellij with module path and modules to include) but I keep getting this error
Exception in thread "main" java.lang.NoClassDefFoundError: javafx/application/Application
at java.base/java.lang.ClassLoader.defineClass1(Native Method)
at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1010)
at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:150)
at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(BuiltinClassLoader.java:855)
at java.base/jdk.internal.loader.BuiltinClassLoader.findClassOnClassPathOrNull(BuiltinClassLoader.java:753)
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(BuiltinClassLoader.java:676)
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:634)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:182)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:519)
at main.Launcher.main(Launcher.java:5)
Caused by: java.lang.ClassNotFoundException: javafx.application.Application
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:636)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:182)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:519)
... 10 more
I also have a Launcher class, which Main method just does Main.main(args), where Main is the class that extends Application.
What can i do more?
This is the main class of my project
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
import java.io.IOException;
public class Main extends Application {
#Override
public void start(Stage primaryStage) {
try {
Parent root = FXMLLoader.load(getClass().getResource("/fxml/InserimentoPorta.fxml"));
primaryStage.setTitle("EP Miner");
primaryStage.setScene(new Scene(root));
primaryStage.show();
}catch (IOException e){
System.out.println(e.getMessage());
System.exit(-1);
}
}
public static void main(String[] args) {
launch(args);
}
}
And there are 3 controllers, one for each of my fxml file (i'm not posting the controllers code because the question would be too long and i don't think it's necessary to solve this problem)

java.lang.NoClassDefFoundError: org/openqa/selenium/firefox/FirefoxDriver at Driverbasic.Driverbasics.main(Driverbasics.java:12)

i am getting the above error .I have import all the libs related to selenium and java .Here is the code that i have written
package Driverbasic;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class Driverbasics {
public static void main (String args [])
{
System.setProperty("webdriver.gecko.driver", "/home/user/Downloads/geckodriver-v0.29.1-linux64");
WebDriver driver = new FirefoxDriver();
}
}
Here is the error i am getting
Exception in thread "main" java.lang.NoClassDefFoundError: org/openqa/selenium/firefox/FirefoxDriver
at Driverbasic.Driverbasics.main(Driverbasics.java:12)
Caused by: java.lang.ClassNotFoundException: org.openqa.selenium.firefox.FirefoxDriver
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
... 1 more
I have attached the screenshot for the same .enter image description here
enter image description here
Any help would be really appreciated .

Apache POI Workbook class not found

First, I want let you know what I'm using:
Eclipse IDE 2018-09 (4.9.0) Java-SE 10
Apache POI 4.0.0-20180907
I don't mixing any JARs files with other version and I add to my project all the JARs in the folder except "poi-examples-4.0.0".
Let take a look of this code:
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Workbook;
public class Program
{
public static void main(String[] args)
{
Workbook workbook = new HSSFWorkbook();
}
}
I getting this error:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/poi/hssf/usermodel/HSSFWorkbook
at Program.main(Program.java:8)
Caused by: java.lang.ClassNotFoundException: org.apache.poi.hssf.usermodel.HSSFWorkbook
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:582)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
... 1 more
And if I'm trying this code:
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
public class Program
{
public static void main(String[] args)
{
Workbook workbook = new XSSFWorkbook();
}
}
I getting this error:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/poi/xssf/usermodel/XSSFWorkbook
at Program.main(Program.java:8)
Caused by: java.lang.ClassNotFoundException: org.apache.poi.xssf.usermodel.XSSFWorkbook
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:582)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
... 1 more
Can someone can explain me what I'm doing wrong?

Categories

Resources