且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Primefaces FileUpload在Spring Boot中不起作用

更新时间:2022-06-06 00:33:39

最后,我使用Apache Commons库使它正常工作.类似地,我们可能会在标准的 web.xml 文件中执行的操作,这就是我的上下文初始化程序:

Finally, I got it working using the Apache Commons library. Similarly that what we might do in a standard web.xml file, that's my context initializer:

@Bean
public ServletContextInitializer initializer() {
    return new ServletContextInitializer() {
        @Override
        public void onStartup(ServletContext servletContext)
                throws ServletException {
            servletContext.setInitParameter("primefaces.THEME", "bluesky");
            servletContext.setInitParameter(
                    "javax.faces.FACELETS_SKIP_COMMENTS", "true");
            servletContext.setInitParameter(
                    "com.sun.faces.expressionFactory",
                    "com.sun.el.ExpressionFactoryImpl");
            servletContext.setInitParameter("primefaces.UPLOADER",
                    "commons");
        }
    };
}

我明确地告诉Primefaces使用 commons 上传器,如docs中所述(另一种选择是使用 native ,这是行不通的.)

I explicitly tell Primefaces to use the commons uploader, like said in docs (the other choice is to use native, which is not working).

然后,只需将这两个依赖项添加到项目中,就可以开始了:

Then, just adding this two dependencies to the project, we're ready to go:

<dependency>
    <groupId>commons-fileupload</groupId>
    <artifactId>commons-fileupload</artifactId>
    <version>1.3</version>
</dependency>
<dependency>
    <groupId>commons-io</groupId>
    <artifactId>commons-io</artifactId>
    <version>2.2</version>
</dependency>

我将线程保持打开状态以基于 native 模式进行响应.

I keep the thread opened for some response based in the native mode.

另请参见: