简体   繁体   English

未找到默认构造函数异常

[英]No default constructor found exception

I'm developing a web application in java spring 4 framework. 我正在Java Spring 4框架中开发Web应用程序。 At one point I'm using FormDataContentDisposition class which is providing by jersey. 有一次我正在使用由jersey提供的FormDataContentDisposition类。 This class used at an endpoint of my REST call like this , 此类在我的REST调用的端点处使用,

@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" 当我进行REST调用时,Apache Tomcat给出了一个异常,说:“无法实例化[com.sun.jersey.core.header.FormDataContentDisposition]:找不到默认构造函数”

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. 由于FormDataContentDisposition没有默认的构造函数,因此我认为也有例外,根据此文章http://javarevisited.blogspot.in/2014/01/why-default-or-no-argument-constructor-java-class .html应该有一个默认的构造函数。 I can't create a default constructor, since this class(FormDataContentDisposition) is inside a jar file. 我无法创建默认的构造函数,因为此类(FormDataContentDisposition)在jar文件中。

Help me to overcome from this problem 帮助我克服这个问题

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. 没有方法可以实例化此类的对象而没有构造函数的参数,因此您需要在Spring 4中弄清楚如何为该类的构造提供参数。

The article you refer to delivers the opinion that ALL classes should have a default constructor. 您引用的文章提出了这样的观点,即所有类都应具有默认构造函数。 It is no kind of rule in Java; 在Java中,这不是一种规则。 I don't even think it qualifies as best practice. 我什至不认为这符合最佳做法。 I also don't think the article has any bearing on your problem. 我也认为本文与您的问题无关。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 类Exception的默认构造函数? - Default constructor of class Exception? 默认构造函数java的抛出异常 - Throw exception for default constructor java Spring @Autowired构造函数给出没有找到默认构造函数 - Spring @Autowired constructor gives No default constructor found Spring MVC没有找到默认构造函数? - Spring MVC no default constructor found? 找不到默认的构造函数; 嵌套异常是java.lang.NoSuchMethodException bean配置 - No default constructor found; nested exception is java.lang.NoSuchMethodException bean configuration 创建名为'application'的bean时出错,找不到默认构造函数;嵌套异常是java.lang.NoSuchMethodException - Error creating bean with name 'application', No default constructor found; nested exception is java.lang.NoSuchMethodException 未找到默认构造函数; 嵌套异常是 java.lang.NoSuchMethodException 与 Spring MVC? - No default constructor found; nested exception is java.lang.NoSuchMethodException with Spring MVC? 找不到默认的构造函数; 嵌套异常org.springframework.test.context.TestContext。 <init> () - No default constructor found; nested exception org.springframework.test.context.TestContext.<init>() 异常:子类ParseObject的“未提供默认构造函数”异常 - Exception: “No default Constructor provided” exception subclassing ParseObject Application构造函数中的JavaFX异常(No Such methods found exception) - JavaFX Exception in Application constructor(No Such method found exception)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM