I want to integrate CXF and Spring for a simple JAX-WS. Below is the maven pom file.
<dependencies>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxws</artifactId>
<version>2.7.6</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http</artifactId>
<version>2.7.6</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http-jetty</artifactId>
<version>2.7.6</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>3.2.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>3.2.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-webapp</artifactId>
</dependency>
</dependencies>
When I run the jetty using maven command. It had some exception like this:
spring java.lang.NoSuchMethodError: org.springframework.core.convert.converter.ConverterRegistry.addConverter(Ljava/lang/Class;Ljava/lang/Class;Lorg/springframework/core/convert/converter/Converter;)V
It seems the problem is CXF and Spring dependencies problems. When I go to the target folders and find out there are two version of Spring with the version I specified and the version CXF depend on. 3.0.7?
If I change the spring version to the lower one and it works.
I just wondering are there any way to solve this if I still want to use the latest version of Spring?
I think I find out the reason. I need also to put spring-core as maven dependency. Because the converter in the exception are in the core dependency.
So when the maven jetty run, there are two version of spring, spring-core is using 3.0.7 which is with CXF, and the other are 3.2.3 which is I specified.
I need to keep consistent with spring version in the project.
Related
We recently upgraded Spring boot to 2.7.3. We have elastic search in one of our modules and hence worked on the necessary code changes for the same too.
Worked fine on local but we got an error while building in QA with following error
Invalid or missing build flavor [oss];
We realized that with AWS elasticsearch/opensearch (version 7.9.3), this caused an issue as there is a recent change in RestHighLevelClient to have an addition validation which only allows default as build flavor for elastic-search.
So decided to downgrade spring-boot-starter-data-elasticsearch to just 2.5.7
https://github.com/spring-projects/spring-data-elasticsearch/issues/2021
This led me to go through adding explicit transitive dependency for many artifacts
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-elasticsearch</artifactId>
<version>2.5.7</version>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-elasticsearch</artifactId>
<version>4.2.7</version>
</dependency>
<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>elasticsearch-rest-high-level-client</artifactId>
<version>7.12.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.elasticsearch/elasticsearch -->
<dependency>
<groupId>org.elasticsearch</groupId>
<artifactId>elasticsearch</artifactId>
<version>7.12.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.elasticsearch.plugin/transport-netty4-client -->
<dependency>
<groupId>org.elasticsearch.plugin</groupId>
<artifactId>transport-netty4-client</artifactId>
<version>7.12.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.elasticsearch.client/elasticsearch-rest-client -->
<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>elasticsearch-rest-client</artifactId>
<version>7.12.1</version>
</dependency>
</dependencies>
But still when I start up my spring application, it is giving me error because some part of spring-auto-configure is which is of version 2.7.3 could not find necessary class because I have downgraded transitive dependency
So wanted to check if someone else has been in same soup as I am
Correct the classpath of your application so that it contains compatible versions of the classes org.springframework.boot.autoconfigure.http.HttpMessageConverters and org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter
Solved it by adding below maven dependency
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
and also by removing the version tag 5.2.3.RELEASE from the below dependency
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
</dependency>
Has anyone successfully got Spring Boot, Spring Data Elasticsearch, and Elasticsearch 5.x to work?
I updated my pom to use spring-data-elasticsearch 3.0.0.RELEASE (just released) which has commit notes in Github saying it supports ES 5.
I was getting some errors which were caused by not having declared a dependency on spring-data-common. After adding without a version, I noticed it was being managed by Spring Boot apparently and pulls in 1.13.7.RELEASE
This causes: java.lang.NoClassDefFoundError: org/springframework/data/mapping/model/Property
I then bumped up spring-data-common to 2.0.0.RELEASE thinking the newest releases of everything should be compatible. That causes an AbstractMethodError exception when the repository is wired.
Can anyone give any tips? Here are the dependencies from my POM
Managed versions from Parent POM:
<spring-boot.version>1.5.7.RELEASE</spring-boot.version>
<spring-cloud.version>Dalston.RELEASE</spring-cloud.version>
From POM from the child module where things don't work
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-commons</artifactId>
<!-- <version>2.0.0.RELEASE</version> -->
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-elasticsearch</artifactId>
<version>3.0.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.elasticsearch</groupId>
<artifactId>elasticsearch</artifactId>
<version>5.5.0</version>
</dependency>
<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>transport</artifactId>
<version>5.5.0</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>
</dependencies>
Whomever edited the title made an inaccurate description. As originally stated, the issue is a "dependency hell". There wasn't missing dependencies but rather a ton of transitive dependencies that all needed versions to be coordinated in magic nonobvious/undocumented ways. – JvmSd121
I once migrated the spring-data-elasticsearch (with ES 2.x) project to use ES 5.x.
I lost the source but I still have the jar here
You guys put me on the right track. I upgraded as follows:
Spring Core (and related): 5.0.0.RELEASE
Spring Boot: 2.0.0.M4
Spring Cloud: Finchley.M2
With those in place, the managed versions get updated as follows:
spring-data-commons: 2.0.0.RC3 (from release-train KAY-RC3)
spring-data-elasticsearch: 3.0.0.RC3 (from release-train KAY-RC3)
elasticsearch and transport: 5.5.2 (meets my 5.x requirement)
We had managed versions of Jackson in our parent pom for other child modules which caused incompatible versions to be pulled in. I overrode those in our Spring Boot projects to the version ${jackson.version} defined in Spring as follows:
spring-jackson-version=2.9.1
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>${spring-jackson.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>${spring-jackson.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${spring-jackson.version}</version>
</dependency>
I'm getting another error from my repo which I think is self-inflicted due to my data model. All the classpath errors seem to have gone away. I'll give another update if I find anything further. What a cf!
Thanks for the tips.
I'm using Spring Boot and spring-boot-starter-jersey, for my application.
Initially I was working on Java 1.7 and everything worked fine.
But when I moved to Java 1.6 it started giving me error.
Caused by: java.lang.UnsupportedClassVersionError:
org/glassfish/jersey/server/ResourceConfig : unsupported classversion 51.0
I don't want to use java 1.7. How can i get rid of this error in java 1.6.
Also, on Spring boot site I couldn't find suitable version of spring-boot-starter-jersey for java 1.6
Below is my POM
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.2.0.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jersey</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
<version>1.2.0.RELEASE</version>
</dependency>
</dependencies>
<properties>
<tomcat.version>7.0.59</tomcat.version>
</properties>
Jersey 2.7 and up is compiled with Java 7. So if you want to use Java 6, you need to use Jersey 2.6. So you will need to get rid of the Jersey starter
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jersey</artifactId>
</dependency>
All the starter does is pull in a bunch of dependencies, it doesn't do anything code-wise. So all you really need to do is replace the dependencies with different versions in your pom. If you look at the actual pom for spring-boot-starter-jersey, you can see everything it pulls in. Below is a revised version of what you should add in place of spring-boot-starter-jersey
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet</artifactId>
<version>${jersey.version}</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.ext</groupId>
<artifactId>jersey-spring3</artifactId>
<version>${jersey.version}</version>
<exclusions>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.jaxrs</groupId>
<artifactId>jackson-jaxrs-json-provider</artifactId>
<version>2.4.4</version>
</dependency>
{jersey.version} is 2.6.
A couple differences is that I am excluding everything Spring from the jersey-spring3. I'm doing this because you are already pulling everything in with the spring-boot-starter-web.
Also the jersey-media-json-jackson used in the Jersey start pom, we can't use that, unless you want to be stuck with using Jackson 1.9. So instead we just pull in underlying Jackson provider jackson-jaxrs-json-provider. The version we are using is the same Jackson version in Spring Boot bom.
The only other thing you need to do is configure the Jackson support for Jersey, that just includes registering the providers. You can just use the following feature.
import com.fasterxml.jackson.jaxrs.base.JsonMappingExceptionMapper;
import com.fasterxml.jackson.jaxrs.base.JsonParseExceptionMapper;
import com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider;
import javax.ws.rs.core.Feature;
import javax.ws.rs.core.FeatureContext;
import javax.ws.rs.ext.MessageBodyReader;
import javax.ws.rs.ext.MessageBodyWriter;
public class JacksonFeature implements Feature {
#Override
public boolean configure(FeatureContext context) {
context.register(JsonParseExceptionMapper.class);
context.register(JsonMappingExceptionMapper.class);
context.register(JacksonJaxbJsonProvider.class,
MessageBodyReader.class, MessageBodyWriter.class);
return true;
}
}
Just register it with your ResourceConfig... register(JacksonFeature.class).
That's really it, Everything should still work the same. The auto configuration should still be in tact. I tested it, not rigorously, but works for a simple startup.
UPDATE
Or as #Andy Wilkinson suggesed, you can keep the spring-boot-starter-jersey, and just set the property <jersey.version>2.6</jersey.version> in your pom. But if you want to use Jackson 2, just exclude jersey-media-json-jackson (as Jersey 2.6 pulls uses Jackson 1.9.3), and just include the jackson-jaxrs-json-provider as mentioned above, and follow the rest of the instructions to configure it.
I'm trying to upgrade an application that's using Spring 2.5.6 to the latest (3.0.3.RELEASE) version and I'm using the Spring repository to find the latest versions of the jars I need:
http://www.springsource.com/repository/app/library/versiondetail?name=org.springframework.spring&version=3.0.3.RELEASE
I'm at version 2.0.8 for spring-mock. I've found documentation that says spring-mock moved into spring-test with 2.5.x but according to the repository spring-test doesn't exist anymore in 3.0.3.RELEASE. I'm also having trouble tracking down what has happened to spring-tx and spring-webmvc-struts since 2.5.6.
Do any of you know what's happened to these jars (i.e. moved, deprecated) and where I can find documentation?
I have all the jars you mention jars currently in a project. I just used Maven, the simplest way to get the jars you are looking for:
<properties>
<org.springframework.version>3.0.3.RELEASE</org.springframework.version>
</properties>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-struts</artifactId>
<version>${org.springframework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>${org.springframework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${org.springframework.version}</version>
<scope>test</scope>
</dependency>