13491

No default constructor found exception

I'm developing a web application in java spring 4 framework. At one point I'm using FormDataContentDisposition class which is providing by jersey. This class used at an endpoint of my REST call like this ,

@RequestMapping(value = "/createArticle/", method = RequestMethod.POST) @Consumes(MediaType.MULTIPART_FORM_DATA) public ResponseEntity<Void> createNewArticle(@FormDataParam("file") InputStream uploadedInputStream, @FormDataParam("file") FormDataContentDisposition fileDetails)

when i make a REST call, Apache Tomcat giving an exception saying, "Failed to instantiate [com.sun.jersey.core.header.FormDataContentDisposition]: No default constructor found"

Since FormDataContentDisposition don't have a default constructor, i think this exceptions comes, also according to this artcle http://javarevisited.blogspot.in/2014/01/why-default-or-no-argument-constructor-java-class.html there should be a default constructor present. I can't create a default constructor, since this class(FormDataContentDisposition) is inside a jar file.

Help me to overcome from this problem

Answer1:

I think you are correct in the cause of the problem. There is no way in which you can instantiate an object of this class without arguments to the constructor, so you need to figure out, in Spring 4, how to feed an argument to the construction of that class and do so.

The article you refer to delivers the opinion that ALL classes should have a default constructor. It is no kind of rule in Java; I don't even think it qualifies as best practice. I also don't think the article has any bearing on your problem.

Recommend

  • Spring + Angular Unable to upload same file twice
  • springboot jackson returns array instead of proper json object
  • Bind a String value to an enum in a @RequestBody entity in Spring Boot
  • 404 response on simple RESTeasy example with Tomcat
  • File download through ajax
  • How to convert Image to multipart file in spring
  • How to insert alt tags dynamically in jsp
  • Is it possible to use an http url as your source location of a Source Filter in DirectShow .Net?
  • Task processing status with a message queue
  • Creating a SOAP proxy?
  • How to port C# Console application to Windows Phone
  • How do I create an image and save it for later to draw as texture in XNA?
  • How can I set a binding to a Combox in a UserControl?
  • Sort List of Strings By Version
  • Problems compiling files using JOGL
  • Parsing a CSV string while ignoring commas inside the individual columns
  • Swing - Get new component under mouseReleased
  • MVC3 Razor - ListBox pre-select not working
  • Set the selected item in dropdownlist in MVC3
  • ilmerge with a PFX file
  • Spring Data JPA custom method causing PropertyReferenceException
  • Can I display google adwords (AdView) in javafx on android
  • Validaiting emails with Net.Mail MailAddress
  • sending/ receiving email in Java
  • Cannot Parse HTML Data Using Android / JSOUP
  • JTable with a ScrollPane misbehaving
  • IndexOutOfRangeException on multidimensional array despite using GetLength check
  • unknown Exception android
  • EntityFramework adding new object to nested object collection
  • Checking variable from a different class in C#
  • Easiest way to encapsulate a HTML5 webpage into an android app?
  • Busy indicator not showing up in wpf window [duplicate]
  • costura.fody for a dll that references another dll
  • Observable and ngFor in Angular 2
  • How to Embed XSL into XML
  • failed to connect to specific WiFi in android programmatically
  • UserPrincipal.Current returns apppool on IIS
  • Conditional In-Line CSS for IE and Others?
  • java string with new operator and a literal
  • How can I use threading to 'tick' a timer to be accessed by other threads?