How to use Jedis Client 3.x with Spring-boot 1.5.x? - spring-boot

I want to use Stream function in Jedis which only available in Jedis 3.x ,but I can not change the Spring boot version to 2.2 for some reasons and now the Springboot version is only 1.5.x:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
<version>1.5.11.RELEASE</version>
</dependency>
If I use Jedis 3.x with SpringBoot1.5.x,
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>3.1.0</version>
</dependency>
it will report errors:
Caused by: java.lang.ClassNotFoundException: redis.clients.util.SafeEncoder
at java.net.URLClassLoader.findClass(URLClassLoader.java:381) ~[na:1.8.0_181]
at java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[na:1.8.0_181]
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349) ~[na:1.8.0_181]
at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[na:1.8.0_181]
... 50 common frames omitted
which is caused by the Jedis version( if changes the version of Jedis to 2.9.x,this error will disappear, but the Stream function can not be used). It is a dilemma.
Does anybody has any suggestion?

Can not use Jedis 3.x with SpringBoot1.5.x, must upgrade the SpringBoot to 2.x.

Related

Does ScyllaDB Support Latest Version of Metrics?

When I launch ScyllaDB for the first time:
Cluster cluster = Cluster.builder().addContactPoints("xx.xxx.xx.xxx").build();
Session session = cluster.connect("my_scylladb_cluster");
System.out.println(session.isClosed());
I get the following error:
===== Using optimized driver!!! =====
Exception in thread "main" java.lang.NoClassDefFoundError: com/codahale/metrics/JmxReporter
at com.datastax.driver.core.Metrics.<init>(Metrics.java:156)
at com.datastax.driver.core.Cluster$Manager.init(Cluster.java:1773)
at com.datastax.driver.core.Cluster.init(Cluster.java:228)
at com.datastax.driver.core.Cluster.connectAsync(Cluster.java:401)
at com.datastax.driver.core.Cluster.connect(Cluster.java:352)
at scylladbX.ScyllaDBXMain.main(ScyllaDBMain.java:12)
Caused by: java.lang.ClassNotFoundException: com.codahale.metrics.JmxReporter
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 6 more
In my Maven POM file I'm using the latest version of Metrics:
<dependency>
<groupId>io.dropwizard.metrics</groupId>
<artifactId>metrics-core</artifactId>
<version>4.2.9</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.dropwizard.metrics/metrics-graphite -->
<dependency>
<groupId>io.dropwizard.metrics</groupId>
<artifactId>metrics-graphite</artifactId>
<version>4.2.9</version>
</dependency>
I noticed that if I downgrade to a much earlier version of Metrics, the problem goes away:
<!-- https://mvnrepository.com/artifact/com.codahale.metrics/metrics-core -->
<dependency>
<groupId>com.codahale.metrics</groupId>
<artifactId>metrics-core</artifactId>
<version>3.0.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.codahale.metrics/metrics-graphite -->
<dependency>
<groupId>com.codahale.metrics</groupId>
<artifactId>metrics-graphite</artifactId>
<version>3.0.0</version>
</dependency>
Does ScyllaDB not support the latest version of Metrics? What is the latest version supported?
Thanks
The DataStax Java Driver documentation here has a section about the problem you saw:
While the driver depends on Metrics 3.2.x, it also works with Metrics 4, with some caveats.
In Metrics 4, JMX reporting was moved to a separate module, metrics-jmx. Because of this you are likely to encounter the following exception at runtime when initializing a Cluster:
Exception in thread "main" java.lang.NoClassDefFoundError: com/codahale/metrics/JmxReporter
at com.datastax.driver.core.Metrics.<init>(Metrics.java:103)
at com.datastax.driver.core.Cluster$Manager.init(Cluster.java:1402)
at com.datastax.driver.core.Cluster.init(Cluster.java:159)
at com.datastax.driver.core.Cluster.connectAsync(Cluster.java:330)
at com.datastax.driver.core.Cluster.connectAsync(Cluster.java:305)
at com.datastax.durationtest.core.DurationTest.createSessions(DurationTest.java:360)
....
Caused by: java.lang.ClassNotFoundException: com.codahale.metrics.JmxReporter
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:582)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:185)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:496)
... 8 more
That document also has suggestions what to do in this case.
In any case, this problem has nothing to do with Scylla (the backend server you want to connect to) - and is just a problem with the Java client ("driver") you are using.

Gatling using JDBC feeder connecting to SQL Server with Windows Authentication throws error "java.lang.NoSuchMethodError"

Learning from this documentation , I tried to use Gatling JDBC feeder to grab data from our SQL Server with Windows Authentication.
I add this dependency in my POM.xml
<!-- https://mvnrepository.com/artifact/dev.code-n-roll.gatling/jdbc-gatling -->
<dependency>
<groupId>dev.code-n-roll.gatling</groupId>
<artifactId>jdbc-gatling_2.12</artifactId>
<version>2.3.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.gatling/gatling-jdbc -->
<dependency>
<groupId>io.gatling</groupId>
<artifactId>gatling-jdbc</artifactId>
<version>3.4.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.microsoft.sqlserver/mssql-jdbc -->
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<version>7.4.1.jre8</version>
</dependency>
My connection string looks like this
import io.gatling.jdbc.Predef._
val databaseUrl = "jdbc:sqlserver://CentralSQLServer:1433;databaseName=CustomerDB;integratedSecurity=true"
I added integratedSecurity=true because the access method to the SQL server is using Windows Authentication, not using username & password. This works fine when I use vanilla Java with JDBC.
Then I define the JDBC Feeder
val mySQLFeeder = jdbcFeeder(databaseUrl, "", "", "SELECT * FROM [CustomerDB].[dbo].[Users]")
I put empty String in username and password sections , since I don't have it.
Running the Gatling test using mvn gatling:test , I see this error is thrown by Gatling
02:05:29.920 [ERROR] i.g.a.Gatling$ - Run crashed
java.lang.NoSuchMethodError: io.gatling.core.feeder.SourceFeederBuilder$.apply(Lio/gatling/core/feeder/FeederSource;Lio/gatling/core/config/GatlingConfiguration;)Lio/gatling/core/feeder/SourceFeederBuilder;
at io.gatling.jdbc.Predef$.jdbcFeeder(Predef.scala:26)
at testCases.Delete.<init>(Delete.scala:49)
... 16 common frames omitted
Wrapped by: java.lang.reflect.InvocationTargetException: null
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at io.gatling.app.Runner.run0(Runner.scala:74)
at io.gatling.app.Runner.run(Runner.scala:60)
at io.gatling.app.Gatling$.start(Gatling.scala:80)
at io.gatling.app.Gatling$.fromArgs(Gatling.scala:46)
at io.gatling.app.Gatling$.main(Gatling.scala:38)
at io.gatling.app.Gatling.main(Gatling.scala)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at io.gatling.mojo.MainWithArgsInFile.runMain(MainWithArgsInFile.java:50)
at io.gatling.mojo.MainWithArgsInFile.main(MainWithArgsInFile.java:33)
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at io.gatling.mojo.MainWithArgsInFile.runMain(MainWithArgsInFile.java:50)
at io.gatling.mojo.MainWithArgsInFile.main(MainWithArgsInFile.java:33)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at io.gatling.app.Runner.run0(Runner.scala:74)
at io.gatling.app.Runner.run(Runner.scala:60)
at io.gatling.app.Gatling$.start(Gatling.scala:80)
at io.gatling.app.Gatling$.fromArgs(Gatling.scala:46)
at io.gatling.app.Gatling$.main(Gatling.scala:38)
at io.gatling.app.Gatling.main(Gatling.scala)
... 6 more
Caused by: java.lang.NoSuchMethodError: io.gatling.core.feeder.SourceFeederBuilder$.apply(Lio/gatling/core/feeder/FeederSource;Lio/gatling/core/config/GatlingConfiguration;)Lio/gatling/core/feeder/SourceFeederBuilder;
at io.gatling.jdbc.Predef$.jdbcFeeder(Predef.scala:26)
at testCases.Delete.<init>(Delete.scala:49)
... 16 more
It looks like Gatling JDBCFeeder method complains about my connection string using integratedSecurity=true since in the documentation we should use username and password. The thing is there are no username and password in my case.
Is there any way to solve this issue?
Thanks.
Thanks #GeorgeLeung and #StephaneLandelle .
The issue is caused by dependency version conflict.
The gatling-jdbc version must align with the gatling-core version.
Change the dependencies in POM.xml to this below does solve the issue.
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<encoding>UTF-8</encoding>
<gatling.version>3.3.1</gatling.version>
<gatling-maven-plugin.version>3.0.5</gatling-maven-plugin.version>
<scala-maven-plugin.version>4.3.1</scala-maven-plugin.version>
<maven-jar-plugin.version>3.2.0</maven-jar-plugin.version>
<scala.version>2.12.10</scala.version>
</properties>
<dependencies>
<dependency>
<groupId>io.gatling.highcharts</groupId>
<artifactId>gatling-charts-highcharts</artifactId>
<version>${gatling.version}</version>
</dependency>
<dependency>
<groupId>io.gatling</groupId>
<artifactId>gatling-app</artifactId>
<version>${gatling.version}</version>
</dependency>
<dependency>
<groupId>io.gatling</groupId>
<artifactId>gatling-recorder</artifactId>
<version>${gatling.version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.microsoft.sqlserver/mssql-jdbc -->
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<version>7.4.1.jre8</version>
</dependency>
</dependencies>
The gatling-app does include the gatling-jdbc , so we don't need to extra add it.

ClassNotFoundException: org.springframework.hateoas.Resource even though I have the dependency added

I have the following in my pom.xml
<dependency>
<groupId>org.springframework.hateoas</groupId>
<artifactId>spring-hateoas</artifactId>
</dependency>
But I still get the following message
Caused by: java.lang.NoClassDefFoundError: org/springframework/hateoas/Resource
at java.lang.Class.getDeclaredMethods0(Native Method) ~[na:1.8.0_191]
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701) ~[na:1.8.0_191]
at java.lang.Class.getDeclaredMethods(Class.java:1975) ~[na:1.8.0_191]
at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:668) ~[spring-core-5.1.5.RELEASE.jar:5.1.5.RELEASE]
... 21 common frames omitted
Caused by: java.lang.ClassNotFoundException: org.springframework.hateoas.Resource
at java.net.URLClassLoader.findClass(URLClassLoader.java:382) ~[na:1.8.0_191]
at java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[na:1.8.0_191]
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349) ~[na:1.8.0_191]
at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[na:1.8.0_191]
... 25 common frames omitted
I tried deleting the contents of the .m2 folder and downloading all the dependencies again. I tried force updating the maven project, but I still get the message when I start the Spring Boot project. Anyone know why I'm getting this even though I have added the dependency?
For Spring Boot use spring-boot-starter-hateoas dependency
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-hateoas</artifactId>
<version>2.1.4.RELEASE</version>
</dependency>
Add following dependency in pom.xml
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-hateoas</artifactId>
<version>2.2.6.RELEASE</version>
</dependency>
Write following method in your controller:-
#GetMapping("/student/{id}")
public EntityModel<Student> getstudent(#PathVariable int id) {
Student student = studentRepo.findById(id).orElse(new Student());
EntityModel<Student> resource=new EntityModel<Student>(student);
Link link=WebMvcLinkBuilder.linkTo(this.getClass()).
slash(studentRepo.findAll()).withSelfRel();
resource.add(link.withRel("all-students"));
return resource;
}
Try restarting container if you added hateoas explicitly, that worked for me.
The ResourceSupport/Resource/Resources/PagedResources group of classes never really felt appropriately named. After all, these types do not actually manifest resources but rather representation models that can be enriched with hypermedia information and affordances. Here’s how new names map to the old ones:
ResourceSupport is now RepresentationModel
Resource is now EntityModel
Resources is now CollectionModel
PagedResources is now PagedModel

java.lang.NoClassDefFoundError: org/springframework/orm/hibernate5/HibernateTransactionManager

I am trying to integrate spring with hibernate and I have spring-orm .4.3.6 jar file in my project.But still I am getting below error :
java.lang.NoClassDefFoundError: org/springframework/orm/hibernate5/HibernateTransactionManager
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
at java.lang.Class.getDeclaredMethods(Class.java:1975)
at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:613)
at org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:524)
at org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:510)
at org.springframework.util.ReflectionUtils.getUniqueDeclaredMethods(ReflectionUtils.java:570)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.getTypeForFactoryMethod(AbstractAutowireCapableBeanFactory.java:697)
Tried googling it.But did not find answer.
Can someone help?
This class is coming out of the spring-orm dependency (notice the hibernate5 package in there. There is equally hibernate3 and hibernate4 packages in the same jar not to break compatibility).
The Maven Coordinates are:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>4.3.10.RELEASE</version>
</dependency>

ElasticSearch 2.0 Java API: java.lang.ClassNotFoundException: org.elasticsearch.common.settings.ImmutableSettings$Builder

I have updated my Spring Boot project to use the new ElasticSearch 2 API and I get this error at startup:
Caused by: java.lang.NoClassDefFoundError: org/elasticsearch/common/settings/ImmutableSettings$Builder
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
at java.lang.Class.getDeclaredMethods(Class.java:1975)
My relevant Maven dependencies are:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-elasticsearch</artifactId>
<version>1.3.0.M5</version>
</dependency>
<dependency>
<groupId>org.elasticsearch</groupId>
<artifactId>elasticsearch</artifactId>
<version>2.0.0-rc1</version>
</dependency>
Do you have any hint on what I am doing wrong?
Thanks
In ES 2.0, the ImmutableSettings class was indeed removed. This issue mentions it and the breaking changes documentation for 2.0 also mention it.
Instead you can now use Settings.builder() instead of ImmutableSettings.builder(). The current implementation of the Settings class can be seen here
All the questions that still use ImmutableSettings are questions about pre-2.0 versions of Elasticsearch.

Resources