No default constructor found exception

[亡魂溺海] 提交于 2019-12-24 02:55:13

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/40113406/no-default-constructor-found-exception

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!