conflicts between spring-mongo and spring-cassandra - spring-boot

1.Work well with spring-mongo in microservice.
2.Work well with spring-cassandra in microservice.
build project with gradle.
but when i add spring-cassandra into spring-mongo,there are errors.even just import spring-cassandra dependencies,without any cassandra
compile "org.springframework.data:spring-cql:1.5.0.M1"
compile "org.springframework.data:spring-data-cassandra:1.5.0.M1"
compile "com.datastax.cassandra:cassandra-driver-core:3.0.1"
The error trace is too long.just take a summary.
throw exceptions
` ``
org.springframework.beans.factory.BeanCreationException
com.datastax.driver.core.exceptions.NoHostAvailableException
not caused by one class.when i run the test with gradle.all testcase throw this exception.and spring boot application cannot start.which worked well before.
and i have not added any java code to call datastax driver to connect cassandra.dont know why there is an exception about cassandra connection.

solve this issue by putting mongo/cassandr repository/model into
different package

Related

Spring Boot 3 and cross platform native-image creation with GraalVM

with Spring Boot 3 release there is lots of advertisement about GraalVM and native-images, so I decided experiment little bit..
With Spring Boot Initializer I quickly created a really simple gradle project (one single rest service that is doing nothing special). With the help of the gradle 'native-image' and JiB plugin, I could quickly get a running state with Spring Boot Application as a normal Java Applicaton and native-image Application (and seen the drastic startup time changes).
While JiB created a Docker Image for me, I tried to deploy the SB3 application to my minikube, there I got the first surprise, while I was working with MacOS M1, the image that I created (based on alpine) was complaining the wrong 'exec format' after little bit reading, I learned while my local GraalVM is MacOS based aarch64 it would not run in alpine and I have to create cross platform image and I have to create Docker images based on destination platform GraalVM (in this case linux/alpine) which I did, I bypassed the original problem and Spring Boot 3 application starts but encounters following problem in the stacktrace.
16:43:45.808 [main] ERROR org.springframework.boot.SpringApplication - Application
run failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with
name 'resourceHandlerMapping': Instantiation of supplied bean failed
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.obtainInstan ceFromSupplier(AbstractAutowireCapableBeanFactory.java:1236)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.obtainFromSupplier(AbstractAutowireCapableBeanFactory.java:1210)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1157)
Caused by: java.lang.IllegalStateException: No ServletContext set
at org.springframework.util.Assert.state(Assert.java:76)
at org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport.resourceHandlerMapping(WebMvcConfigurationSupport.java:581)
at org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport__BeanDefinitions.lambda$getResourceHandlerMappingInstanceSupplier$7(WebMvcConfigurationSupport__BeanDefinitions.java:166)
at org.springframework.util.function.ThrowingBiFunction.apply(ThrowingBiFunction.java:68)
at org.springframework.util.function.ThrowingBiFunction.apply(ThrowingBiFunction.java:54)
Now I tried to look as much as possible what 'native-image' plugin does (while native-image and Spring Boot 3 application runs on my Mac Book), I can't figure out what is the Delta. I think it has to do with 'reflection-config'. 'native-image' plugin created a 'reflect-config.json' and it contains the following lines.
{
"name": "resourceHandlerMapping",
"parameterTypes": [
"org.springframework.web.accept.ContentNegotiationManager",
"org.springframework.format.support.FormattingConversionService",
"org.springframework.web.servlet.resource.ResourceUrlProvider"
]
}
I think should be relevant for the problem, but this file is in the classpath and it is not changing the outcome(I can also see that 'WebMvcConfigurationSupport__BeanDefinitions.java' is also generated and is in the classpath).
One thing I have to say, while the shear number of dependencies Spring Boot needs, I didn't place the whole dependencies in the classpath but I created a fat jar (shadowJar plugin), which includes all my code and dependencies, may be this causing the problem.
'native-image' in my cross platform docker image, is able to create the application with this fat jar but it throws the above mentioned exception.
Anyway, can anybody give any tips to solve this problem.
Or how can diagnose such a problem in GraalVM and native-image?

WebSphere Liberty and Eclipselink SDO

I am porting an old IBM Process Server application to IBM WebSphere Liberty. It contains a lot of code based on Service Data Objects (SDO). I have some good working code, running as standalone Java, using JDK8. I am using eclipselink 2.7.7, specifically 2 jar files;
eclipselink.jar
commonj.sdo_2.1.1v20111051852.jar
I have built this code into a Servlet to handle SOAP requests, and packaged it, along with other code, into an EAR file, which I deployed under IBM WebSphere Liberty 20. It doesn't work. There seems to be a clash with the Liberty version of EclipseLink.
If I deploy the code as a WAR file, and add a classloader of "PARENT_LAST", the code works fine.
However, if I try to deploy the code in an EAR file, and set a classloader of "PARENT_LAST" for the ear file, I get this error;
[ERROR ] CWWKZ0106E: Could not start web application S21.
[ERROR ] CWWKZ0002E: An exception occurred while starting the application S21. The exception message was: com.ibm.ws.container.service.state.StateChangeException: java.lang.LinkageError: loader constraint violation in interface itable initialization: when resolving method "org.eclipse.persistence.jpa.PersistenceProvider.getProviderUtil()Ljavax/persistence/spi/ProviderUtil;" the class loader (instance of com/ibm/ws/classloading/internal/ParentLastClassLoader) of the current class, org/eclipse/persistence/jpa/PersistenceProvider, and the class loader (instance of org/eclipse/osgi/internal/loader/EquinoxClassLoader) for interface javax/persistence/spi/PersistenceProvider have different Class objects for the type javax/persistence/spi/ProviderUtil used in the signature
Does anyone know whether I can replace the IBM Liberty implementation of EclipseLink with my version 2.7.7 version?
My application also uses JPA, which is working fine under Liberty, so I don't want to break that.
Any help / guidance appreciated... it's been a very long saturday.
PS:
I tried running the java code using only the SDO library (commonj.sdo_2.1.1v20111051852.jar), and relying on the WebSphere Liberty runtime jars to provide Eclipselink functionality, and I got the following errors, which is why I then moved to adding the "matching pair" of Eclipselink / SDO jars mentioned above;
Caught Exception : org.eclipse.persistence.internal.security.PrivilegedAccessHelper.getSystemPropertyBoolean(Ljava/lang/String;Z)Z
java.lang.NoSuchMethodError: org.eclipse.persistence.internal.security.PrivilegedAccessHelper.getSystemPropertyBoolean(Ljava/lang/String;Z)Z
at org.eclipse.persistence.sdo.helper.SDOHelperContext.<init>(SDOHelperContext.java:93)
at org.eclipse.persistence.sdo.helper.SDOHelperContext$DefaultHelperContextResolver.getHelperContext(SDOHelperContext.java:1432)
at org.eclipse.persistence.sdo.helper.SDOHelperContext.getHelperContext(SDOHelperContext.java:492)
at org.eclipse.persistence.sdo.helper.SDOHelperContext.getHelperContext(SDOHelperContext.java:471)
at org.eclipse.persistence.sdo.helper.SDOHelperContext.getHelperContext(SDOHelperContext.java:456)
at org.eclipse.persistence.sdo.helper.delegates.SDOXMLHelperDelegator.getXMLHelperDelegate(SDOXMLHelperDelegator.java:178)
at org.eclipse.persistence.sdo.helper.delegates.SDOXMLHelperDelegator.load(SDOXMLHelperDelegator.java:78)
at com.ebs.solas2021.port.adapter.ui.SOAPRequestHandler.main(SOAPRequestHandler.java:237)
It's amazing what you find whgen you re-read the documentation in the cold light of a new day. It turns out that it's possible to install a JPA 2.2 Container on Liberty, while supplying one's own implementation of EclipseLink. Works like a charm.
Documented here: https://openliberty.io/blog/2018/06/29/full_java_ee_8_liberty_18002.html

Dropwizard, swagger and in-memory hiverunner/hiveqlunit integration

I am having some trouble trying to run an in-memory hive while writing tests for a dropwizard swagger app. I have tried both hiverunner and hiveqlunit.
There are 2 types of tests. One is for testing dropwizard/swagger API endpoints using dropwizard integration testing (no need for hive here) and the other is for testing the hive integration where I need to hit the api and setup an in-memory hive to query and verify data is stored in hiveDB (psql).
The two in-memory hive dependencies (Note that I am using one at a time) always have some kind of conflict with the existing dropwizard and swagger dependencies. I am guessing it has something to do with jersey but I've tried a lot of things and still no luck.
I can run in-memory hive just fine and do all CRUD if I am not hitting the dropwizard/swagger api. But I just can't get the two services to play along at the moment.
Versions in Maven:
io.dropwizard:dropwizard-core version: 0.9.2
com.smoketurner:dropwizard-swagger version: 0.9.2-3
com.facebook.presto.hive:hive-apache-jdbc version: 0.13.1-3
com.klarna:hiverunner version: 3.0.0
OR
org.finra.hiveqlunit:hiveQLUnit version: 1.0
dropwizard-swagger uses org.reflections:reflections:jar:0.9.10 and com.klarna:hiverunner uses org.reflections:reflections:jar:0.9.8.
When I didn't exclude anything, I got the following:
java.lang.NoSuchMethodError: org.reflections.util.ClasspathHelper.forPackage(Ljava/lang/String;[Ljava/lang/ClassLoader;)Ljava/util/Collection;
So I tried excluding org.reflections:reflections from hiverunner and I got the 3 Exceptions:
java.lang.RuntimeException: javax.servlet.ServletException: io.dropwizard.jersey.setup.JerseyServletContainer-73437222#8a344094==io.dropwizard.jersey.setup.JerseyServletContainer,1,false
Caused by: A MultiException has 3 exceptions. They are:
1. java.lang.NullPointerException
2. java.lang.IllegalStateException: Unable to perform operation: method inject on com.sun.jersey.json.impl.provider.entity.JSONRootElementProvider$App
3. java.lang.IllegalStateException: Unable to perform operation: create on org.glassfish.jersey.message.internal.MessageBodyFactory
Then I tried excluding org.reflections:reflections from dropwizard-swagger and added a separate dependency for org.reflections:reflections by adding the following dependency to my pom.xml:
<dependency>
<groupId>org.reflections</groupId>
<artifactId>reflections</artifactId>
<version>0.9.10</version>
</dependency>
And got the following:
java.lang.NoClassDefFoundError: com/google/common/base/MoreObjects
So I added the latest guava (version 20.0) and then it gives me another error. This seems like dependency hell.
Has anyone ever encountered this problem before? It seems like dropwizard and hiverunner do not play along well. Maybe it has to do with the versioning of jersey 1 & 2.
I got some other error regarding jackson-databind, so I did some research and found out I had to have the same version for the following dependencies:
com.fasterxml.jackson.core:jackson-databind (from `dropwizard`)
com.fasterxml.jackson.module:jackson-module-scala (from `hiverunner/hiveqlunit`)
And now I am back to the previous 3 Exceptions...
Any help will be appreciated.
Edit: Found out that hiveqlunit is using the following:
com.sun.jersey:jersey-server:jar:1.9
Which is one of the last versions before moving to the following maven dependency:
org.glassfish.jersey.core:jersey-server
It is having conflicts with dropwizard's org.glassfish.jersey.core:jersey-server:jar:2.22.
How can i resolve this conflict?

Running Spring Boot container fails with File not found exception for hadoop-core-1.2.1

This question has been posted before but I am not sure if it was ever resolved. I am facing exactly the same issue as (19608050 - same title). I am using spring-boot-started-web:1.1.0.RC1 ,spring-data-hadoop 1.0.2.RELEASE and hbase 0.94.3. I can see the hadoop-core-1.2.1 jar under the lib\ in the jarred file which I deploy.
I have a small sample project which I posted on: https://github.com/klopes/test-spring-boot-hadoop.git. It compiles (and unit tests worked successfully) but it fails to deploy.
If I start the app by clicking on the main class in my IDE, it runs without any exceptions and the jar is loaded, also gradle runBoot works just fine. Seems like a spring boot class loader bug.
#EnableAutoConfiguration(exclude = {VelocityAutoConfiguration.class})
You are using a very old version of Spring Boot. Your app runs for me with Spring Boot 1.1.0.BUILD-SNAPSHOT, at least the context starts with no errors. There are no test cases so I'm not sure if it's actually working though.

Struts2 Dispatcher initialization failure with maven - jetty

I have the following problem:
I am working on a Web-Project using Struts2 with Tiles supported by a combination of Hibernate and Spring. In addition I am using Maven (which I'm new to) and the jetty server container. So my coworker told me what to do: just check out the project from the svn-repository and run the command (sudo) mvn jetty:run. According to my coworker this should work just fine, as it does when he checks out the project. But I always get the same error:
2011-08-22 10:09:20,568 ERROR org.apache.struts2.dispatcher.Dispatcher.error:38 -
Dispatcher initialization failed
Unable to load configuration. - [unknown location]
I already tried to re-check out the project, cleaned and updated maven, but still, the same error.
I think it has something to do with a missing struts2 .jar-file, but I thought maven downloads all necessary libraries automatically. Please give me a hint what could be missing, I'm sure it's something simple I overlooked.
Thanks in advance.

Resources