问题描述
我正在用Java Spring 4框架开发一个Web应用程序.有一次,我正在使用由jersey提供的FormDataContentDisposition类.此类在我的REST调用的端点处使用,
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)
当我进行REST调用时,Apache Tomcat给出了一个异常消息,无法实例化[com.sun.jersey.core.header.FormDataContentDisposition]:找不到默认构造函数"
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"
由于FormDataContentDisposition没有默认构造函数,因此我认为也有例外,根据此文章 http://javarevisited.blogspot.in/2014/01/why-default-or-no-argument-constructor-java-class.html 应该有一个默认的构造函数.我无法创建默认的构造函数,因为此类(FormDataContentDisposition)在jar文件中.
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.
帮助我克服这个问题
推荐答案
我认为问题的原因是正确的.没有方法可以实例化此类的对象而没有构造函数的参数,因此您需要在Spring 4中弄清楚如何为该类的构造提供参数.
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.
您所引用的文章提出了这样的观点,即所有类都应具有默认构造函数.在Java中,这不是一种规则.我什至不认为这符合最佳做法.我也认为这篇文章与您的问题无关.
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.
这篇关于未找到默认构造函数异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!