Spring MVCはアップロードのたびにtomcatのホームディレクトリにファイルをアップロードしますが、削除されることはありません。Spring MVCはTomcatのホームディレクトリにファイルをアップロードします
は二つの問題、
- TomcatプロセスがPRODでTomcatのホームディレクトリへの書き込み権限を持っていませんがあります。だから許可が拒否されたエラーを取得します
- 私たちが許可を与えると、多くのファイルが作成されますが、決して削除されません。
Spring MVCはアップロードのたびにtomcatのホームディレクトリにファイルをアップロードしますが、削除されることはありません。Spring MVCはTomcatのホームディレクトリにファイルをアップロードします
は二つの問題、
一つの解決策は、その継承customizeRegistration()
メソッドをオーバーライドAbstractAnnotationConfigDispatcherServletInitializer
を拡張することで、バイト[] JSPから春にMVCコントローラとしてファイルのアップロードを取得する方法はあります。
MultipartConfigElement
クラスのオブジェクトは、マルチパートに関連する動作を設定するために提供することができます。
import javax.servlet.MultipartConfigElement;
import javax.servlet.ServletRegistration;
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;
public class SpringMvcInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {
. . .
@Override
protected void customizeRegistration(ServletRegistration.Dynamic registration) {
registration.setMultipartConfig(
new MultipartConfigElement(LOCATION, MAX_FILE_SIZE, MAX_REQUEST_SIZE, FILE_SIZE_THRESHOLD)
);
}
private static final String LOCATION = "C:/temp/"; // Temporary location where files will be stored
private static final long MAX_FILE_SIZE = 1024 * 1024 * 5; // 5MB : Max file size.
// Beyond that size spring will throw exception.
private static final long MAX_REQUEST_SIZE = 1024 * 1024 * 20; // 20MB : Total request size containing Multi part.
private static final int FILE_SIZE_THRESHOLD = 0; // Size threshold after which files will be written to disk
}
参照:Spring MVC 4 File Upload Example using Servlet 3 MultiPartConfigElement
これは、ファイルのアップロードやマップのための独立した外部のフォルダを持っている方が良いでしょうTomcatのそのフォルダを場所として指定します。
<Context path="/uploads" docBase="C:/uploads/" />
そして、それはからアクセスできるようになります:
localhost:8080/uploads
http://serverfault.com/questions/13523/configure-tomcat-to-use-a-different-temp-/13698#13698 – fantaghirocco
-Djava.io.tmpdir =/tmp/tomcat7-tomcat7-tmpを設定しました。しかし、ファイルはこのディレクトリには行きませんが、まだtomcatのホームディレクトリである/ var/lib/tomcat7に行きます。 –
おそらく '$ CATALINA_TMPDIR'は' java.io.tmpdir'にバインドされていませんか?このケースにリンクshoudが適用されます – fantaghirocco