Configure morphia and mongotemplate - spring-boot

I am trying to configure both morphia and mongotemplate in the same application. I have added the following dependencies in pom.xml
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>
<dependency>
<groupId>org.mongodb.morphia</groupId>
<artifactId>morphia</artifactId>
<version>1.3.2</version>
</dependency>
When I run the application, I get the below error as both dependencies have mongo driver.
The method's class, com.mongodb.ConnectionString, is available from the following locations:
jar:file:/C:/Users/.m2/repository/org/mongodb/mongodb-driver-core/4.1.1/mongodb-driver-core-4.1.1.jar!/com/mongodb/ConnectionString.class
jar:file:/C:/Users/.m2/repository/org/mongodb/mongo-java-driver/3.4.0/mongo-java-driver-3.4.0.jar!/com/mongodb/ConnectionString.class
The class hierarchy was loaded from the following locations:
com.mongodb.ConnectionString: file:/C:/Users/.m2/repository/org/mongodb/mongodb-driver-core/4.1.1/mongodb-driver-core-4.1.1.jar
Removing either one of them gives the following error.
java.lang.IllegalArgumentException: Could not find class [com.mongodb.MongoClientSettings]
How can I fix this? Thanks in advance!

Try using a modern version of Morphia that uses the 4.0 driver. You can find the details on the website. The current current is 2.2.2 which has seen many improvements and updates from 1.3.2.

Related

Method does not exist: org.elasticsearch.client.RequestOptions$Builder.setRequestConfig(Lorg/apache/http/client/config/RequestConfig;)

I am creating Hibernate Search 6 application with Spring Boot 2.3.4
I am facing this error while I try to build my application -
Description:
An attempt was made to call a method that does not exist. The attempt was made from the
following location:
org.hibernate.search.backend.elasticsearch.client.impl.ElasticsearchClientImpl.setPerRequestSocketTimeout(ElasticsearchClientImpl.java:198)
The following method did not exist:
org.elasticsearch.client.RequestOptions$Builder.setRequestConfig(Lorg/apache/http/client/config/RequestConfig;)Lorg/elasticsearch/client/RequestOptions$Builder;
The method's class, org.elasticsearch.client.RequestOptions$Builder, is available from the following locations:
jar:file:/C:/Users/pranali.rasal/.m2/repository/org/elasticsearch/client/elasticsearch-rest-client/7.6.2/elasticsearch-rest-client-7.6.2.jar!/org/elasticsearch/client/RequestOptions$Builder.class
The class hierarchy was loaded from the following locations:
org.elasticsearch.client.RequestOptions.Builder:
file:/C:/Users/pranali.rasal/.m2/repository/org/elasticsearch/client/elasticsearch-rest-client/7.6.2/elasticsearch-rest-client-7.6.2.jar
Action:
Correct the classpath of your application so that it contains a single, compatible version of org.elasticsearch.client.RequestOptions$Builder
Following are the dependencies that i have added -
<dependency>
<groupId>org.hibernate.search</groupId>
<artifactId>hibernate-search-mapper-orm</artifactId>
<version>6.1.5.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate.search</groupId>
<artifactId>hibernate-search-backend-elasticsearch</artifactId>
<version>6.1.5.Final</version>
</dependency>
Let me know if I missing something.
This is all explained here: https://docs.jboss.org/hibernate/stable/search/reference/en-US/html_single/#gettingstarted-framework-spring-boot-dependency-versions
Basically, Spring Boot is managing your dependencies, and it's forcing an older version of the Elasticsearch client. You need to force it back to the version Hibernate Search expects (a newer version, 7.16.x).
And just to clarify, this has nothing to do with the Elasticsearch server version that I've seen mentioned in other answers. This is strictly about your client.
This is probably due to incompatible version of the elasticsearch dependency. From https://docs.jboss.org/hibernate/stable/search/reference/en-US/html_single/#getting-started-compatibility it seems you need 7.10 or 7.16 but you have 7.6 dependency. Also check server version to be sure.
hibernate-search-backend-elasticsearch
is internally dependent on elasticsearch-rest-client-7.6.2.jar
And the method
org.elasticsearch.client.RequestOptions$Builder.setRequestConfig(Lorg/apache/http/client/config/RequestConfig;)Lorg/elasticsearch/client/RequestOptions$Builder;
it is trying to find is in later versions of low level client.
Temporary solution will be to exclude 7.6.2 and include latest version of elasticsearch-rest-client-7.6.2.jar -
<dependency>
<groupId>org.hibernate.search</groupId>
<artifactId>hibernate-search-backend-elasticsearch</artifactId>
<exclusions>
<exclusion>
<groupId>org.elasticsearch.client</groupId>
<artifactId>elasticsearch-rest-client</artifactId>
</exclusion>
</exclusions>
</dependency>
and including,
<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>elasticsearch-rest-client</artifactId>
<version>7.10.0</version>
</dependency>
Since this is a temporary, I am not sure if this is reliable.
Please let me know in case there is a better solution.

How to get Spring to use older version of Guava for specific Dependency, but newer version for "main" project

I have a dependency in my SpringBoot project:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-cluster-zookeeper</artifactId>
<version>1.0.2.RELEASE</version>
</dependency>
Which requires Guava 16.01
However, my "main" project which I'm including cluster-zookeeper in requires Guava 28.2
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>28.2-jre</version>
</dependency>
When I run SpringBoot App, I get error:
The following method did not exist:
com.google.common.util.concurrent.MoreExecutors.sameThreadExecutor()Lcom/google/common/util/concurrent/ListeningExecutorService;
The method's class, com.google.common.util.concurrent.MoreExecutors, is available from the following locations:
jar:file:/blah/.m2/repository/com/google/guava/guava/28.2-jre/guava-28.2-jre.jar!/com/google/common/util/concurrent/MoreExecutors.class
It was loaded from the following location:
file: /blah/.m2/repository/com/google/guava/guava/28.2-jre/guava-28.2-jre.jar
Action:
Correct the classpath of your application so that it contains a single, compatible version of com.google.common.util.concurrent.MoreExecutors
It seems like a version conflict issue where Spring tries to get cluster-zookeeper to use newer Guava version, when it require older one. How can I get this to work? I.e use 16.01 Guava for ONLY cluster-zookeeper while keeping 28.2 dependency for my main project?

#Webservice annotation exception on weblogic

I am trying to run my application which contain JAX WS (2.1) Webservice using JDeveloper 11g R2(11.1.2.3.0) in JDK 1.6.0_31-b05. The error is coming from #WebService annotation present on the class.
When I am running the application, I am getting below error,
java.lang.IllegalArgumentException: Argument(s) "type" can't be null.
at com.sun.xml.bind.api.TypeReference.<init>(TypeReference.java:89)
at com.sun.xml.ws.model.RuntimeModeler.processDocWrappedMethod(RuntimeModeler.java:758)
at com.sun.xml.ws.model.RuntimeModeler.processMethod(RuntimeModeler.java:678)
at com.sun.xml.ws.model.RuntimeModeler.processClass(RuntimeModeler.java:428)
at com.sun.xml.ws.model.RuntimeModeler.buildRuntimeModel(RuntimeModeler.java:277)
at com.sun.xml.ws.server.EndpointFactory.createSEIModel(EndpointFactory.java:363)
at com.sun.xml.ws.server.EndpointFactory.createEndpoint(EndpointFactory.java:202)
at com.sun.xml.ws.api.server.WSEndpoint.create(WSEndpoint.java:496)
at com.sun.xml.ws.api.server.WSEndpoint.create(WSEndpoint.java:539)
at weblogic.wsee.jaxws.JAXWSDeployedServlet.getEndpoint(JAXWSDeployedServlet.java:183)
It seems that embedded Web Logic is using the internal libraries instead of provided one from JDK. The classes RuntimeModeler or TypeReference are present in JDK rt.jar starts with package com.sun.xml.ws.internal. Weblogic is picking these classes from glassfish.jaxb_1.0.0.0_2-1-12.jar & glassfish.jaxws.rt_1.2.0.0_2-1-5.jar, but these jars are not part of my application.
I have already used weblogic.xml with below tag,
<prefer-web-inf-classes>true</prefer-web-inf-classes>
I tried adding jaxws-api.jar & jws-api.jar in DefaultDomain/lib directory, but that didn't work
Any clue how to resolve this exception or how to force weblogic to use jdk runtime classes? The same application work properly on stand alone weblogic.
I had the same problem and found the answer here: http://www.intropro.com/resources/blog/66-argument-s-type-can-t-be-null
In short - the problem appears because you have jaxb-impl in you classpath which overrides WebLogics own jaxb, You may not explicitly refer to this dependency from your pom.xml, but some of your other dependencies do.
In my case I had apache-cxf as maven dependency and it had jaxb 2.1.13 as sub-dependency with scope "compile". All I had to do is exclude this apaches jaxb and add my own dependency with scope "provided" to explicitly use WebLogics jaxb.
in pom.xml it looked like this:
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxws</artifactId>
<version>2.7.2</version>
<exclusions>
<exclusion>
<artifactId>jaxb-impl</artifactId>
<groupId>com.sun.xml.bind</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<scope>provided</scope>
<version>2.1.13</version>
</dependency>
You can use eclipses "Dependency Hierarchy" tab in pom.xml view or simply command line "mvn dependency:tree" to find out how jaxb-impl made it to your classpath.
In my case, i had a typo in the arguments of the operation, where two arguments had the same webParam name. Modified that and deployed, issue was resolved.
Have you tried listing the correct jar in the manifest class-path: attribute? You could also put the jdk classes in the app and try using a FilteringClassLoader to specify which classes to use from the app rather than system classloader.
http://docs.oracle.com/cd/E15051_01/wls/docs103/programming/classloading.html#wp1097263

java.lang.ClassNotFoundException: org.hibernate.cache.EhCacheProvider

java.lang.ClassNotFoundException: org.hibernate.cache.EhCacheProvider
In my pom.xml dependency for ecahce is like below
<dependency>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache</artifactId>
<version>1.5.0</version>
</dependency>
but still i am facing the problem classNotFound Exception
Please help me out iam trying this out from past 2 days
The dependency you're looking for is the following I think (Perhaps a different version)
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-ehcache</artifactId>
<version>3.6.2.Final</version>
</dependency>
I searched for the missing class using Maven Central's search site:
http://search.maven.org/#search|ga|1|fc%3A%22org.hibernate.cache.EhCacheProvider%22
When I ran into this problem, it was because I was trying to update the version of hibernate. When moving from hibernate 3.2 to 3.3, the packages split. I had tried to replace hibernate with hibernate-core. Reverting back to the full hibernate package (at 3.2 level) fixed my problem.
During my next round of updates, I will probably need to replace the full hibernate package with hibernate-core and hibernate-ehcache as referenced above.

Cannot find SerialAddress class in Apache Mina 2.0.2

I added the below dependencies in my project POM file and the SerialAddress class is no where to be found from the downloaded mina-core.2.0.2.jar.
<dependency>
<groupId>org.apache.mina</groupId>
<artifactId>mina-core</artifactId>
<version>2.0.2</version>
</dependency>
the package org.apache.mina.transport.serial doesnt even exist. Please advice me on the correct Dependency.
It looks like this class is not part of mina-core. Some exploration lead to the existence of Apache Mina Serial Communication Support.
So I guess you would want to add the dependency for mina-transport-serial.
<dependency>
<groupId>org.apache.mina</groupId>
<artifactId>mina-transport-serial</artifactId>
<version>2.0.2</version>
</dependency>

Resources