Tomcat seems to reference an older version of a dependency (spring-web) - java

I'm using IntelliJ with the IvyIdea plugin. I added spring as dependency, rev 4.3.16 (the one my team uses).
After successfully building the project (which is a rest api), I tried to deploy it as an exploded war using tomcat 8.5.12 (again, the one my team is using).
When the deployment is running I get this exception:
NoSuchMethodException: org.springframework.web.accept.ContentNegotiationManager.getStrategy(Ljava/lang/Class;)
Reading the official documentation, I can see that the getStrategy method was introduced on Spring 4.3 so not sure what I'm doing wrong. I've tried cleaning the Ivy cache but it didn't help.
Any help would be appreciated.

Related

MessageBodyProviderNotFoundException after building with maven shade plugin [solved]

Hi I'm building a java REST client application that uses json. There's a conflict in my dependencies: one essential dependency requires jackson databind/core/annotations 2.10.1, another essential dependency uses an older version 2.2.2.
When running the app in Eclipse, this led to a MessageBodyProviderNotFoundException. The problem was that maven included version 2.2.2 instead of 2.10.1. So I use dependency management to resolve the conflict and include version 2.10.1. Within Eclipse this solved the issue and the app runs fine.
But after building the app with the maven shade plugin, the standalone app still fails with the MessageBodyProviderNotFoundException. The exception is thrown in a part of the code requiring version 2.10.1, not in the part depending on version 2.2.2.
Any thoughts? Thanks in advance!
EDIT: I checked my local maven repository and it only contains version 2.10.1. So the problem is not that the jar somehow still includes version 2.2.2.
Problem solved. Running the app within Eclipse apparently doesn't require explicitly registering a JacksonJsonProvider, but running the standalone app does:
ClientConfig config = new ClientConfig().connectorProvider(new ApacheConnectorProvider()).register(new JacksonJsonProvider());
Client client = ClientBuilder.newBuilder().withConfig(config) ...

Java classloader with same jar

I know that many subject speak about classpath loader and transitive dependancy but i m little confused.
I m working on a legacy application that use spring 2.0.5 and spring-ws and all work fine from the beginning of the project to now.
And recently we are faced to a runtime problem with a an exception like methodnotfoundexception.
In fact we see that spring-ws depend on spring-2.5. So maven transitive dependancy add spring 2.5 in my webinf/lib directory near spring 2.0.5
But i dont understand why all working fine during many years and now why weblogic decide to load spring2.5 before spring2.0.5 and cause this error?
We have correct the problem and now i m looking for same jar with different version and do build failure when i have a conflit to avoid dependancy problem in the future.
But i just want to understand why weblogic decide to load one or another jar ? Because if its alphabetical order, same jar will be loaded all the time, but in my exemple the order change...
So i don t understand clearly whats happened.
Thanks by advance;)
While it is documented that WEB-INF/classes is loaded before WEB-INF/lib, the documentation is not clear in cases like yours - where there are sibling copies of Spring in the WEB-INF/lib.
In Tomcat it is alphabetical, but looks like Websphere, Jboss and Weblogic are random. See https://stackoverflow.com/a/5817890/327426
From some threads on the Oracle forums, the recommendation is to run the Classloader Analysis Tool available at http://docs.oracle.com/cd/E23943_01/web.1111/e13706/classloading.htm#BABHJGJJ for your app and see the results. This tool will identify classloading conflicts.
See similar issue at https://community.oracle.com/thread/2387921?tstart=0
This post from 2009 http://www.coderanch.com/t/472496/BEA-Weblogic/Loading-order-jar-WEB-INF on Weblogic v9.2 states "Checking the logs I see the .jars in WEB-INF/lib are being loaded in reverse alphabetical order". This may or may not be true for your version
Another option is to use Maven to bypass the transitive import being packaged in the WAR

virgo tomcat server runs on 3.1.0.release of spring my web app depends on 3.2.0. how do i resolve this?

I want to migrate my web app from standard war to WAB using Virgo Tomcat Server.
The std war file depends on spring 3.2.0.RELEASE and VTS has 3.1.0.RELEASE.
I tried to deploy all the spring 3.2.0 jars and my web app specific jars in usr directory of virgo.
And when i try to deploy the war in pickup folder with import to 3.2.0 spring release, there is a version conflict between the 3.1.0 and 3.2.0 releases.
Will the highest available version of jar from the specified range not be picked up?
ex., there are 2 jars
1. spring-core version 3.1.0.RELEASE
2. spring-core version 3.2.0.RELEASE
And the manifest has an import saying
org.springframework.core;version="[3,4)"
shouldnt it pick up 3.2.0.RELEASE
The VTS FAQ explains how to upgrade the version of Spring used by webapps:
How can I change the version of Spring framework in the user region?
I'm not entirely sure I understand everything that it is saying, but it does say that Spring 3.2 is supported in Virgo 3.6.0. Also, it seems to be saying that the upgrade doesn't happen auto-magically by some version selection mechanism. You apparently have to delete the old JARs.

Running Multiple Spring Projects with different Spring Versions on Eclipse

Configuration problem: You cannot use a spring-security-2.0.xsd or spring-security-3.0.xsd schema with Spring Security 3.1. Please update your schema declarations to the 3.1 schema.
Offending resource: class path resource [authentication-context.xml]
In my Eclipse workspace are a set of Mavenised Spring projects on Spring verion 3.0.6..
It's a fairly large, complicated application, about a year old, with a parent pom and 6/7 sub-poms for different components. I'll title it Project A for now.
Project A has two webapps within it, a public based website and a backoffice administration area.
Recently a seperate application was built for Project A to interact with via REST calls.
However this new application, Project B runs on Spring 3.1.1. This is in the same Eclipse workspace.
Project A's customer website and Project B ran fine on the same tomcat, there were no confused dependencies.
But now that development has started on Project A's backoffice interacting with Project B, there is a conflict, in the Spring security versions when Tomcat is launched.
Current solutions we've attempted have failed, but we haven't tried updating the
Spring version in Project A (fairly sure things will break and not sure it's worth the time retesting) and
downgrading Spring in Project B seems like a horrible precedent to set.
Anyone have any experience with this?
Any help is appreciated :-)

Using (Scala) library from Java Web App, getting NoClassDefFoundError

I've been working on a rather "standard" Java web application for a long time now. I develop in Eclipse using Eclipse's server plugin to run the app in Tomcat. The app's setup is straight forward: Spring for bootstrapping, Wicket for web, Hibernate for ORM, Maven for dependency management.
Today I have added Akka 2.0 to the project. I added it to my POM as per the manual:
<dependency>
<groupId>com.typesafe.akka</groupId>
<artifactId>akka-actor</artifactId>
<version>2.0.2</version>
</dependency>
Maven finds the dependency and I can see it showing up in the Maven dependencies in Eclipse's package explorer. The referenced Scala Library also shows up (version 2.9.2 as it seems).
I can use the library just as one would expect: Eclipse finds the classes, I can jump to source files etc. Everything works perfectly. But once I start the app and it comes across any part of the program with references to Akka it throws a NoClassDefFoundError.
Since all other libraries still work as expected, my best guess is that is has something to do with the fact that Akka is a library developed in Scala. Since I've hardly used Scala myself though, I could not find any solution to the issue myself and Google isn't really that helpful when it comes to such generic exceptions.
Do you have any advice?
Verify that the required library (AKKA) is in your deployment assembly under Eclipse: open the project's properties and look for "Deployment Assembly" on the left.
[I'm using Eclipse Indigo]
You could verify the presence (or lack) of the expected jar file by examining the deployment under tomcat.

Categories