无法实例化bean类[multipart.MultipartFile]:指定的类是org.springframework.beans.BeanUtils.instantiateClass

时间:2016-01-06 18:34:10

标签: java spring hibernate file-upload

我想在我的本地网站上传文件,我使用Spring和Hibernate(我不使用Maven)。

我做了一个表格:

<form class="text-center" action="<c:url value="/createRessource.do"/>" enctype="multipart/form-data" method="POST">
    <h4 class="bleucolor">Titre de la ressource (20 caractères maximum) : </h4>
    <input class="col-lg-4 text-center col-lg-offset-4" type="text" name="titre" maxlength="20"/> <br> <br> <br>
    <h4 class="bleucolor">Description de la ressource (1024 caractères maximum) : </h4>
    <textarea name="description" rows=10 cols=50 maxlength="1024" ></textarea><br><br><br>
    <h4 class="bleucolor"> Pièce jointe :</h4>
    <input class="col-lg-4 text-center col-lg-offset-4" type="file" name="file" /><br><br><br>
    <h4 class="bleucolor"> Tags de la ressource : </h4>
    <c:forEach var="model" items="${sessionScope.tags}">
        <input type="checkbox" name="tagsRessource" value="${model.getIdtag()}" id="${model.getIdtag()}"/>
        <label class="font18" for="${model.getIdtag()}">&thinsp;${model.getLibelle()}&thinsp;</label>
    </c:forEach><br><br><br>
    <input class="text-center avioletbackground rosebtn btn btn-success btn-lg" type="submit"/>
</form>

我有一些输入,标题,描述,文件和标签。

我已添加

<!-- Configure the multipart resolver -->
    <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
    <!-- one of the properties available; the maximum file size in bytes -->
    <property name="maxUploadSize" value="5000000"/>
</bean>

在我的dispatcher-servlet.xml中。

我的控制器可能不完美,因为当我开始时,我只做Controller,DAO和Model,我忘记了所有服务,但我的函数“createRessource”就像:

public ModelAndView createRessource(HttpServletRequest request, HttpServletResponse response, @RequestParam(value="file", required=true) MultipartFile file){
    ApplicationContext ctx = new GenericXmlApplicationContext("applicationContext.xml");
    String resultat = null;
    RessourceHome bean = (RessourceHome) ctx.getBean("RessourceHome");
    String titre = request.getParameter("titre");
    String description = request.getParameter("description");
    String fichierUpload = request.getParameter("file");
    String[] tagsRessource = request.getParameterValues("tagsRessource");
    String fichierName = file.getName();
    String fichierType = file.getContentType();

    try {
        byte[] bytes = fichierUpload.getBytes();
        BufferedOutputStream stream = new BufferedOutputStream(new FileOutputStream(new File("fichier")));
        stream.write(bytes);
        stream.close();            
        resultat = bean.ajouterRessource(titre, description, bytes, tagsRessource, fichierName, fichierType);
    } catch (Exception e) {
        return new ModelAndView("creationRessource");
    }
    if (resultat == null) {
        String erreur = "Création de l'annonce réussie";            
        return new ModelAndView("creationRessource", "erreur", erreur);
    } else {        
        return new ModelAndView("creationRessource", "erreur", resultat);
    }       
}

我的函数“ajouterRessource”将ressource添加到数据库中。 一开始,我不知道MyltipartFile类型存在于Java中。它工作,但我找不到我上传的文件的名称和内容类型,并将其保存在数据库中。

现在,当我提交表单时,我有一个错误:

janv. 06, 2016 7:08:41 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [dispatchers] in context with path [/jobEISTI] threw exception [Request processing failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.web.multipart.MultipartFile]: Specified class is an interface] with root cause
org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.web.multipart.MultipartFile]: Specified class is an interface
    at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:101)
    at org.springframework.web.servlet.mvc.multiaction.MultiActionController.newCommandObject(MultiActionController.java:520)
    at org.springframework.web.servlet.mvc.multiaction.MultiActionController.invokeNamedMethod(MultiActionController.java:466)
    at org.springframework.web.servlet.mvc.multiaction.MultiActionController.handleRequestInternal(MultiActionController.java:408)
    at org.springframework.web.servlet.mvc.AbstractController.handleRequest(AbstractController.java:153)
    at org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:48)
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:900)
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:827)
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:874)
    at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:790)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:646)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:314)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Unknown Source)

我的/ WEB-INF / lib中没有“jsp-api - * .jar”。 我认为它来自MultipartFile但我不知道我应该做什么。拜托,你能帮助我吗?

非常感谢你

0 个答案:

没有答案