简体   繁体   中英

java.lang.NoSuchFieldError: com/fasterxml/jackson/annotation/JsonInclude$Include.USE_DEFAULTS

I am using spring 5.3.7 and when I start my application, it returns the error below:

Instantiation of bean failed; nested exception is
org.springframework.beans.BeanInstantiationException: Failed to instantiate
[org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter]:
Constructor threw exception; nested exception is java.lang.NoSuchFieldError:
com/fasterxml/jackson/annotation/JsonInclude$Include.USE_DEFAULTS

I am using jackson-annotations-2.10.3.jar which implements the USE_DEFAULTS Enum. I hope some one can help me.

You've code that is referencing a field that no longer exists in the class files.

The solution is to clean out all the class files and compile everything from fresh.

If you still get the same error after recompiling everything, then you're probably compiling against one version of an external library and using another at runtime.

What you need to do now is first identify the class that is causing the problem and then run your application with the (-verbose:class) command line option. It will dump a lot of class loading information on your standard out and you'll be able to find out where the problematic class is exactly loaded from.

You should share your source code of dependency injection. However go through this one. Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: .

I am not sure, but you should once check for the annotations like @Service, @Controller, @Respository, there are chances that you have missed any one of the annotations. just check it carefully, it might help you out.

To deal with this error, we have to clear all .class files and recompile to ensure that all files are up to date.

If this error still exists at runtime, it may be that the dependency referenced at compile time is different from the runtime version. Here, it is necessary to check whether the various paths and versions are wrong.

Maven projects generally execute mvn clean.

Hope your problem can be solved

Try cleaning your old build and rebuild your project, atleast it works for me!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM