"NoSuchMethodError getHttpServletMapping" after springboot upgrade - java

I upgraded from springboot 2.1.3 to 2.2.0. So far things works fine but I noticed when I make a rest request that returns a 400, instead of getting the json response I get the error:
[Tomcat].[localhost] : Exception Processing ErrorPage[errorCode=0, location=/error]
java.lang.NoSuchMethodError: javax.servlet.http.HttpServletRequest.getHttpServletMapping()Ljavax/servlet/http/HttpServletMapping;
The funny thing is I get this only when I start the app from Intellij using an emdedded tomcat. (create a mvn profile with "spring-boot:run")
So,
With standalone tomcat, it works fine everywhere
With embedded tomcat, and only if I start from Intellij I get this error.
But I can do the same thing from command line with
mvn spring-boot:run
which then I have no error ?! As suggested on another post I upgraded my IntelliJ to latest version but didn't help

i think you have to upgrade the version of ur tomcat emdedded , there is a version mismatch.
Spring Boot 2.1.X uses Tomcat 9 which has the Servlet API v4.
But Spring Boot Web 2.1.X still incorporates Servlet API v3.1.
OR
Change tomcat version proprety
<properties>
<tomcat.version>8.5.37</tomcat.version>
<properties>
NB:The tomcat.version property is a normal Maven property in your pom.xml. Just add the tomcat.version to your existing Maven properties

I fixed the problem.
Changing property tomcat.version didn't help, so I omitted it and added this to the child pom (trick is it does not work in parent pom). Also note that the version is 2.2.4 and not 2.2.0
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<version>2.2.4.RELEASE</version>
</dependency>

Just wanted to mention another "solution", because I just faced the same problem, after upgrading to Spring Boot 2.4.0
My App is running on Java 11, Spring Boot 2.4.0 AND JakartaEE Api 8.0.0
For a long time I ignored the Jakarta Version, because I found nothing regarding my problem and this dependency in the web.
But after upgrading JakartaEE to 9.0.0 everything worked out fine.
<dependency>
<groupId>jakarta.platform</groupId>
<artifactId>jakarta.jakartaee-api</artifactId>
<version>9.0.0</version>
</dependency>
That was the solution for my problem :) maybe it helps others.

Related

Getting ClassNotFoundException: com.sun.ws.rs.ext.RuntimeDelegateImpl after upgrading Axis2 library

Recently we have upgraded axis2 library in our project. We have upgraded it to 1.7.9 from 1.6.2
and since then we are facing below issue.
java.lang.RuntimeException: java.lang.ClassNotFoundException: com.sun.ws.rs.ext.RuntimeDelegateImpl
at javax.ws.rs.ext.RuntimeDelegate.findDelegate(RuntimeDelegate.java:122)
at javax.ws.rs.ext.RuntimeDelegate.getInstance(RuntimeDelegate.java:91)
at javax.ws.rs.core.UriBuilder.newInstance(UriBuilder.java:69)
at javax.ws.rs.core.UriBuilder.fromUri(UriBuilder.java:80)
at javax.ws.rs.core.UriBuilder.fromUri(UriBuilder.java:99)
at org.glassfish.jersey.client.JerseyWebTarget.<init>(JerseyWebTarget.java:71)
at org.glassfish.jersey.client.JerseyClient.target(JerseyClient.java:290)
at org.glassfish.jersey.client.JerseyClient.target(JerseyClient.java:76)
at com.xyz.MyClass.method1(MyClass.java:55)
As you can see our MyClass.method1() method call JerseyClient.target() which is in jersey-client library (Version 2.23.1) which internally
calls methods of javax.ws.rs-api library ((Version 2.0.1).
RuntimeDelegate class of that library is trying to load RuntimeDelegateImpl at runtime
which is jersey-bundle. But I dont know how its related to Axis2 library. Could you please help me out finding the root cause of this issue ?
I have found similar issue in SO but actual root cause is not mentioned there.
Link : Error when updating Axis2 web services from version 1.5.6 to 1.6.3
Thanks
For maven project, addding below dependency fixed issue for me in the pom.xml file under dependencies.
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-client</artifactId>
<version>1.12</version>
</dependency>

Liberty Websphere cannot load javax.transaction.Transactional when using java 11

After updating to Java 11 we get the following message:
[4/3/20, 11:47:09:184 CEST] 0000002d com.ibm.ws.classloading.internal.util.FeatureSuggestion I CWWKL0084W: The javax.transaction.TransactionManager class could not be loaded. Try enabling the jdbc-4.0 feature or a newer version of the feature in the server.xml file.
We are already using jdbc-4.3 (had the same message on 4.2 as well). The application itself does not give any errors that I can see. The application is made with maven that has the compile plugin configured with 11.
There are no problems when compiling and running tests for the application on java 11, and this only appears when deployed to liberty. Should we explicitly include a dependency for this in the war, or is this an issue that should be fixed in liberty?
From later releases on, Java EE is not included any more. The transaction classes are in the javax.transaction package.
Adding the following dependency should solve it:
<dependency>
<groupId>javax.transaction</groupId>
<artifactId>jta</artifactId>
<version>1.1</version>
</dependency>
(Not sure if it helps with your deployment, but it works with Spring Boot 2)

java.lang.ClassNotFoundException: org.springframework.security.oauth2.client.token.AccessTokenRequest on Weblogic 12c

I have built application on Spring Framework, build it with maven, package it as an EAR and deploy it to Weblogic 11g, and everything works fine.
However, when I try to deploy the same package to Weblogic 12c, I get the following exception.
java.lang.ClassNotFoundException: org.springframework.security.oauth2.client.token.AccessTokenRequest
Why does the Weblogic version upgrade introduces the dependency to this class? The dependency isn't even packaged in the EAR.
I think it has something to do with this dependency, which is used for token based authentication
<dependency>
<groupId>com.auth0</groupId>
<artifactId>java-jwt</artifactId>
<version>2.2.0</version>
</dependency>
What is the problem, and what is generally the best workflow to diagnose these sort of problems systematically?

java.lang.IllegalArgumentException: Jetty ALPN/NPN has not been properly configured

Getting java.lang.IllegalArgumentException: Jetty ALPN/NPN has not been properly configured, while using gRPC(google pub/sub) to publish/consumes messages from Kafka.
Try adding a runtime dependency on netty-tcnative-boringssl-static. See gRPC's SECURITY.md. Note that the version of netty-tcnative necessary changes over time; you should look at the version of the document for a particular release (e.g., this is for 1.2.0).
Finally, went back to boot class class path approach. Prefixed the jetty-alpn.jar to boot class path and it starts working fine in cloud foundry now.
Adding the ALPN client JAR which matches my JDK version fixed this issue for me. In eclipse, you need to set up the jar as a bootstrap entry for the tomcat server.
You can find more info about it here : https://medium.com/#Parithi/jetty-alpn-npn-has-not-been-properly-configured-solution-418417ee6502
As suggested by google, use jetty container instead of tomcat, this solution works, but in our production, applications deployed on tomcat container, but of course I need it to work on tomcat in production.
On debugging the gRPC code, found that guava version causing the issue, updated the guava version 18.0, (where in some classes missed in previous versions), solved the problem , but failed while deploying in CF
Customized emebed-tomcat-core, and it works fine consistently, but again, team say no to custom tomcat container.
Java –jar apm-asset-xxxx.jar – works fine locally, but need to provide a custom command to CF start, didn’t have luxury to change the CF start process.
Finally, trick, the class loader to use tcnative-boring-ssl, library instead of tomcat-core library at runtime, by providing the following dependency in pom.xml. For the past 3 days, this solution is working CF.
org.springframework.boot
spring-boot-starter-web
org.hibernate
*
org.apache.tomcat.embed
tomcat-embed-core
org.apache.tomcat.embed
tomcat-embed-core
provided
Maven manifest plugin to promote the tc-native library to the top in the classloader.
In POM, try to place the gRPC dependency before the spring boot dependency (the order of dependencies matters). I did that and the issue was solved. For example:
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-language</artifactId>
<version>0.13.0-beta</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

Jython 2.7.0 with jersey

I was using Jython standalone version 2.5.3 in my REST application. It was working fine. When I upgraded to Jython 2.7.0, I am getting the following exception,
javax.servlet.ServletException: org.glassfish.jersey.server.ContainerException: javax.xml.transform.TransformerFactoryConfigurationError: Provider org.python.apache.xalan.processor.TransformerFactoryImpl not found
Java xml classes were packaged and distributed with version 2.7.0. But if I understand it correctly Java SE comes with these classes. This issue is raised as a bug here. In order to avoid this exception add the xalan processor dependency in your pom.xml
<dependency>
<groupId>xalan</groupId>
<artifactId>xalan</artifactId>
<version>2.7.1</version>
</dependency>
Another solution would be to upgrade to the latest version of the jython-standalone jar. This issue is fixed in the latest release 2.7.1

Categories