How to overcome the error NoSuchFieldError: PATCH - java

I have crated a project using spring mvc which includes hibernate and jpa. When i try to run that program got an error. Please help. Thank you.
Exception :
javax.servlet.ServletException: Servlet execution threw an exception
Root Cause :
java.lang.NoSuchFieldError: PATCH
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:808)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)

Did you mark your spring dependency as 'provided' on maven, and then run your code on the app server against a different version of spring? If so this is probably the cause
If your app server provides spring library, ensure the declared maven dependency version matches

Even I faced the same problem for first trial with of Spring MVC what I figured out that a Class name MimeType was missing (i.e org.springframework.util.MimeType) you can solve this by adding spring-core-4.0.0.RELEASE.jar file.
I think this would solve your problem cause it worked with me.

Related

NoSuchMethodError in org.json.JSONObject after kubernetes upgrade from 1.21 to 1.23

I don't know if the kubernetes upgrade has anything to do with the problem, but it's the only change I know of between the time the application was working as expected and when it started throwing this exception.
I have some code in a Spring Boot app that adds a List<Object> to a JSONObject. The line looks like this:
jsonObject.put("some_name", someList);
This code hasn't been touched in a year, but suddenly started throwing this exception after a k8s upgrade from 1.21 to 1.23:
org.springframework.web.util.NestedServletException: Handler dispatch failed; nested exception is java.lang.NoSuchMethodError: 'org.json.JSONObject org.json.JSONObject.put(java.lang.String, java.util.Collection)' at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1082)
[...]
Caused by: java.lang.NoSuchMethodError: 'org.json.JSONObject org.json.JSONObject.put(java.lang.String, java.util.Collection)' at com.example.service.MyClass.convertToJson(MyClass.java:109)
The k8s upgrade also included a change from Java 17.0.5+8 to Java 17.0.6+10, but everything runs as expected locally using both of those JDK versions.
I ran a mvn dependency tree -Dverbose and couldn't find anything weird there either. These were the only entries that had to do with json.
org.json:json:jar:20220320
org.springframework.boot:spring-boot-starter-json:jar:2.6.4
I'm out of ideas for what might be causing this issue, so any suggestions on what to look at next are welcome.
It could be that the version of org.json:json included in your project is out of date, and doesn't include the put(String, Collection) method you're trying to use. Try updating this dependency to a more recent version and seeing if that resolves the issue. It's also possible there are some other dependencies in your project which conflict with org.json:json or override it with an older version - check for any similarly named libraries (e.g., json-simple instead of org.json). You may also want to check the version of Spring Boot you're using, as this might be incompatible with the org.json library you're trying to use.

Spring Error- BeanDefinitionParsingException

I'm getting the following error since I added neo4j to my spring mvc project (add default packages like spring-context, spring-webmvc, etc).
org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: AnnotationConfigUtils.processCommonDefinitionAnnotations(…) is not public! Make sure you're using Spring 3.2.5 or better. The class was loaded from file:/Users/mariamdost/Downloads/sts-bundle/pivotal-tc-server-developer-3.1.1.RELEASE/base-instance/wtpwebapps/CodeChallenge/WEB-INF/lib/spring-context-3.1.1.RELEASE.jar.
Offending resource: ServletContext resource [/WEB-INF/spring/appServlet/servlet-context.xml]; nested exception is java.lang.IllegalStateException: AnnotationConfigUtils.processCommonDefinitionAnnotations(…) is not public! Make sure you're using Spring 3.2.5 or better. The class was loaded from file:/Users/mariamdost/Downloads/sts-bundle/pivotal-tc-server-developer-3.1.1.RELEASE/base-instance/wtpwebapps/CodeChallenge/WEB-INF/lib/spring-context-3.1.1.RELEASE.jar.
org.springframework.beans.factory.parsing.FailFastProblemReporter.error(FailFastProblemReporter.java:68)
org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:85)
As the error says I then deleted the default spring-context (3.1.1) and added again and it got rid of that error but then I ran into even more errors. The next error was that spring-expression and spring-context were of different versions so I fixed it by adding spring-expression and excluding spring-expression from neo4j. Then I ran into the final error:
Java.Lang.NoSuchMethod: tried to access method org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingletonMutex()
The last error I cannot find any solution. So reverted back to my initial state and I'm wondering is there another db I can use that will work with my current project setup? If not then how can I fix the current error I have? Any help would be greatly appreciated. Thanks in advance.
Seems like you have added some incompatible spring jars. The java.lang.NoSuchMethod error suggests that the expected method is not found in the dependent class . You would need to have look at the classes that you have added and correct them.

AspectJ on Confluence

Hello we are running Confluence 5.5.1 and we would like to start working with aop programming. The plugin that utilises aop throws an
BeanPostProcessor before instantiation of bean failed; nested exception is java.lang.NoClassDefFoundError: org/aspectj/lang/reflect/AjTypeSystem
because aspectj is not part of the confluence.
I tried to add the aspectjrt 1.6.11 in the $CONFLUENCE_HOME/confluence/WEB-INF/lib without success. Then extracted the jar atlassian-plugins-osgi-3.0.15.jar in order to include the aspectjrt in the osgi-framework-bundles.zip but still no success.
Is there some other workaround I can do in order to be able to work with aspectj?
The plugin breaks when insert <aop:aspectj-autoproxy/> to an .xml in the META-INF folder.
Check this thread in Answers, it seems to be the same issue
https://answers.atlassian.com/questions/5352
Regards,
Gorka

Spring Boot Starter Integration and Starter WS not playing well together?

I'm working on a spike to try to exercise a number of technologies with spring boot (1.1.6.RELEASE), gradle (2.1) and Java 1.8. So we are looking at supporting some old style SOAP Web Service calls as well as Spring Integration. So to get off the ground I was looking at working with the example for producing a web service (http://spring.io/guides/gs/producing-web-service/) and adding spring integration into the mix.
When I did this though and try to hit the WSDL location I am now seeing this stack trace :
2014-09-22 09:53:17.823 ERROR 15188 --- [nio-8080-exec-1] a.c.c.C.[.[.[.[messageDispatcherServlet] : Servlet.service() for servlet[messageDispatcherServlet] in
context with path [] threw exception [Request processing failed; nested exception is java.lang.AbstractMethodError: org.apache.xerces.dom.DeferredDocumentImpl.getXmlStandalone()Z] with root cause
java.lang.AbstractMethodError: org.apache.xerces.dom.DeferredDocumentImpl.getXmlStandalone()Z
at com.sun.org.apache.xalan.internal.xsltc.trax.DOM2TO.setDocumentInfo(DOM2TO.java:377)
at com.sun.org.apache.xalan.internal.xsltc.trax.DOM2TO.parse(DOM2TO.java:131)
at com.sun.org.apache.xalan.internal.xsltc.trax.DOM2TO.parse(DOM2TO.java:98)
at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transformIdentity(TransformerImpl.java:699)
at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(TransformerImpl.java:743)
at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(TransformerImpl.java:357)
at org.springframework.ws.transport.http.WsdlDefinitionHandlerAdapter.handle(WsdlDefinitionHandlerAdapter.java:144)...
Looking around this looks to be related to the Xerces implementation that is pulled in for Integration. You can reproduce this by taking the example Producing a SOAP web service and changing the dependency section to look like this :
dependencies {
compile("org.springframework.boot:spring-boot-starter-ws")
compile("wsdl4j:wsdl4j:1.6.1")
jaxb("com.sun.xml.bind:jaxb-xjc:2.2.4-1")
compile(files(genJaxb.classesDir).builtBy(genJaxb))
compile("org.springframework.boot:spring-boot-starter-integration")
}
Basically adding compile("org.springframework.boot:spring-boot-starter-integration") and then try hitting the WSDL at http://:/ws/countries.wsdl. (running gradle bootRun)
Now arguably this may not be the best way to do this and maybe I should just look to spring integration to expose the endpoint, but has anyone else seen and dealt with this?
Thanks in advance
Tristan
Note I did add the compile "org.apache.ws.xmlschema:xmlschema-core:2.1.0" dep
Here is my jar list from the lib directory
aopalliance-1.0.jar
aspectjrt-1.8.2.jar
aspectjweaver-1.8.2.jar
classmate-1.0.0.jar
commons-codec-1.2.jar
commons-httpclient-3.0.1.jar
commons-io-2.4.jar
hibernate-validator-5.0.3.Final.jar
jackson-annotations-2.3.0.jar
jackson-core-2.3.4.jar
jackson-databind-2.3.4.jar
jboss-logging-3.1.1.GA.jar
jcl-over-slf4j-1.7.7.jar
jdom-1.0.jar
jul-to-slf4j-1.7.7.jar
log4j-over-slf4j-1.7.7.jar
logback-classic-1.1.2.jar
logback-core-1.1.2.jar
rome-1.0.0.jar
rome-fetcher-1.0.0.jar
slf4j-api-1.7.7.jar
snakeyaml-1.13.jar
spring-aop-4.0.7.RELEASE.jar
spring-beans-4.0.7.RELEASE.jar
spring-boot-1.1.6.RELEASE.jar
spring-boot-autoconfigure-1.1.6.RELEASE.jar
spring-boot-starter-1.1.6.RELEASE.jar
spring-boot-starter-aop-1.1.6.RELEASE.jar
spring-boot-starter-integration-1.1.6.RELEASE.jar
spring-boot-starter-logging-1.1.6.RELEASE.jar
spring-boot-starter-tomcat-1.1.6.RELEASE.jar
spring-boot-starter-web-1.1.6.RELEASE.jar
spring-boot-starter-ws-1.1.6.RELEASE.jar
spring-context-4.0.7.RELEASE.jar
spring-core-4.0.7.RELEASE.jar
spring-expression-4.0.7.RELEASE.jar
spring-integration-core-4.0.3.RELEASE.jar
spring-integration-file-4.0.3.RELEASE.jar
spring-integration-http-4.0.3.RELEASE.jar
spring-integration-ip-4.0.3.RELEASE.jar
spring-integration-stream-4.0.3.RELEASE.jar
spring-jms-4.0.7.RELEASE.jar
spring-messaging-4.0.7.RELEASE.jar
spring-oxm-4.0.7.RELEASE.jar
spring-retry-1.1.0.RELEASE.jar
spring-tx-4.0.7.RELEASE.jar
spring-web-4.0.7.RELEASE.jar
spring-webmvc-4.0.7.RELEASE.jar
spring-ws-core-2.2.0.RELEASE.jar
spring-ws-support-2.2.0.RELEASE.jar
spring-xml-2.2.0.RELEASE.jar
tomcat-embed-core-7.0.55.jar
tomcat-embed-el-7.0.55.jar
tomcat-embed-logging-juli-7.0.55.jar
validation-api-1.1.0.Final.jar
wsdl4j-1.6.1.jar
xercesImpl-2.4.0.jar
xmlschema-core-2.1.0.jar
Looks like for the WSDL generation you should provide this dependency:
compile "org.apache.ws.xmlschema:xmlschema-core:2.1.0"
Which is optional from the Spring WS and looks like there is no appropriate implementation in your environment.
UPDATE
Try to add xalan too:
compile "xalan:xalan:2.7.1"
https://groups.google.com/forum/#!topic/google-web-toolkit/07rVeEkCtyU
Or do some tricks with Xerses: java.lang.AbstractMethodError: org.apache.xerces.dom.ElementImpl.getTextContent()Ljava/lang/String

Initialization of bean failed; nested exception is java.lang.NoSuchFieldError: org/springframework/core/convert/TypeDescriptor.NULL

I have upgraded spring jars from 3.0.x to 3.2.x version in my web application. Target environment is Websphere Application Server.
I am getting the following error when I try to hit the welcome page of the webapp in the browser.
Error creating bean with name 'org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping#0':
Initialization of bean failed; nested exception is java.lang.NoSuchFieldError:
org/springframework/core/convert/TypeDescriptor.NULL
It looks like some jar/jars in the build path are dependent on spring 3.0.x. I am not sure though. Will be helpful if anyone could out point the same.
I would also like to know how do I exclude dependency of other jars on spring 3.0.x in dispatcher-servlet.xml. Or should I upgrade any jar?
I am also trying to look for the culprit of the problem.
try this command on windows (if you are using maven)
mvn dependency:tree | find "springframework:" | find ":3.0"
or on *ix
mvn dependency:tree | grep "springframework:" | grep ":3.0"
that should be the culprit.
or manually issue
mvn dependency:tree > dep.txt
and view/edit dep.txt and search for ":3.0" (this will find other, non-spring, libraries as well.
I happened to have find solution of my own problem.
I solved my original problem by removing old spring 3.0.x jars which were still there in
WEB-INF/lib directory (but not in class path).
Second thing and answer to my second problem is that, In a Spring 3.2.x jar or above environment, Ajax call with content-type application/json do not support calls to url with .htm/.html extensions as web-app server throws 406 error. I had to change url extensions to anything else (.json I used for clarity).
Though there could be a different solution as well, but after searching a lot this is what proved to be a quick fix for me. Thanks for all the help.

Categories