web-dev-qa-db-ja.com

一時的なアップロード場所が無効です

JavaとSpring MVC(およびMySQLデータベースにリンクするために休止状態になります)を使用してWebアプリを開発しています。 私の一時的なアップロード場所は有効ではありませんというエラーです。回避策として、私は

  • C:\ Temp \
  • C:\ temp \
  • C:/ temp /
  • / WEB-INF/tmp
  • C:\ Users\Default\AppData

ここに私が得ているエラーがあります

org.springframework.web.multipart.MultipartException: Could not parse multipart servlet request; nested exception is Java.io.IOException: The temporary upload location [C:\Users\take\Eclipse\sts-bundle\pivotal-tc-server-developer-3.1.4.RELEASE\base-instance\work\Catalina\localhost\ToolManagementSystem\WEB-INF\tmp] is not valid
at org.springframework.web.multipart.support.StandardMultipartHttpServletRequest.parseRequest(StandardMultipartHttpServletRequest.Java:99)
at org.springframework.web.multipart.support.StandardMultipartHttpServletRequest.<init>(StandardMultipartHttpServletRequest.Java:77)
at org.springframework.web.multipart.support.StandardServletMultipartResolver.resolveMultipart(StandardServletMultipartResolver.Java:76)
at org.springframework.web.servlet.DispatcherServlet.checkMultipart(DispatcherServlet.Java:1073)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.Java:912)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.Java:877)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.Java:966)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.Java:868)
at javax.servlet.http.HttpServlet.service(HttpServlet.Java:648)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.Java:842)
at javax.servlet.http.HttpServlet.service(HttpServlet.Java:729)
at org.Apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.Java:292)
at org.Apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.Java:207)
at org.Apache.Tomcat.websocket.server.WsFilter.doFilter(WsFilter.Java:52)
at org.Apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.Java:240)
at org.Apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.Java:207)
at org.Apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.Java:212)
at org.Apache.catalina.core.StandardContextValve.invoke(StandardContextValve.Java:106)
at org.Apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.Java:502)
at org.Apache.catalina.core.StandardHostValve.invoke(StandardHostValve.Java:141)
at org.Apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.Java:79)
at org.Apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.Java:616)
at org.Apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.Java:88)
at org.Apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.Java:522)
at org.Apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.Java:1095)
at org.Apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.Java:672)
at org.Apache.Tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.Java:279)
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)
Caused by: Java.io.IOException: The temporary upload location [C:\Users\take\Eclipse\sts-bundle\pivotal-tc-server-developer-3.1.4.RELEASE\base-instance\work\Catalina\localhost\ToolManagementSystem\WEB-INF\tmp] is not valid
    at org.Apache.catalina.connector.Request.parseParts(Request.Java:2751)
    at org.Apache.catalina.connector.Request.getParts(Request.Java:2685)
    at org.Apache.catalina.connector.RequestFacade.getParts(RequestFacade.Java:1083)
    at org.springframework.web.multipart.support.StandardMultipartHttpServletRequest.parseRequest(StandardMultipartHttpServletRequest.Java:84)
    ... 30 common frames omitted

そして、ここに私の初期化子と設定があります:

public class Initializer implements WebApplicationInitializer {

private static final String LOCATION = "/WEB-INF/tmp";
private static final int MAX_FILE_SIZE = 2097152;
private static final int MAX_REQUEST_SIZE = 2097152;
private static final int FILE_SIZE_THRESHOLD = 0;

public void onStartup(ServletContext servletContext) throws ServletException {
    AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
    ctx.register(MvcConfiguration.class);
    servletContext.addListener(new ContextLoaderListener(ctx));

    ctx.setServletContext(servletContext);

    Dynamic servlet = servletContext.addServlet("dispatcher", new DispatcherServlet(ctx));
    servlet.addMapping("/");
    servlet.setLoadOnStartup(1);
    servlet.setMultipartConfig(getMultipartConfigElement());
}

public MultipartConfigElement getMultipartConfigElement(){
    MultipartConfigElement multipartConfigElement = new MultipartConfigElement(LOCATION, MAX_FILE_SIZE, MAX_REQUEST_SIZE, FILE_SIZE_THRESHOLD);
    return multipartConfigElement;
  }
}

@Configuration
@ComponentScan(basePackages = "...*")
@EnableWebMvc
@EnableTransactionManagement
@PropertySource("classpath:application.properties")
@PropertySource("classpath:views.properties")
public class MvcConfiguration extends WebMvcConfigurerAdapter {
private static final String PROPERTY_NAME_DATABASE_DRIVER = "db.driver";
private static final String PROPERTY_NAME_DATABASE_PASSWORD = "db.password";
private static final String PROPERTY_NAME_DATABASE_URL = "db.url";
private static final String PROPERTY_NAME_DATABASE_USERNAME = "db.username";

private static final String PROPERTY_NAME_HIBERNATE_DIALECT = "hibernate.dialect";
private static final String PROPERTY_NAME_HIBERNATE_SHOW_SQL = "hibernate.show_sql";
private static final String PROPERTY_NAME_ENTITYMANAGER_PACKAGES_TO_SCAN = "entitymanager.packages.to.scan";
private static final String PROPERTY_NAME_HIBERNATE_HBM2DDL_AUTO = "hibernate.hbm2ddl.auto";



@Resource
private Environment env;

@Bean
public DataSource dataSource() {
    DriverManagerDataSource dataSource = new DriverManagerDataSource();

    dataSource.setDriverClassName(env.getRequiredProperty(PROPERTY_NAME_DATABASE_DRIVER));
    dataSource.setUrl(env.getRequiredProperty(PROPERTY_NAME_DATABASE_URL));
    dataSource.setUsername(env.getRequiredProperty(PROPERTY_NAME_DATABASE_USERNAME));
    dataSource.setPassword(env.getRequiredProperty(PROPERTY_NAME_DATABASE_PASSWORD));

    return dataSource;
}

@Bean
public LocalSessionFactoryBean sessionFactory() {
    LocalSessionFactoryBean sessionFactoryBean = new LocalSessionFactoryBean();
    sessionFactoryBean.setDataSource(dataSource());
    sessionFactoryBean.setPackagesToScan(env.getRequiredProperty(PROPERTY_NAME_ENTITYMANAGER_PACKAGES_TO_SCAN));
    sessionFactoryBean.setHibernateProperties(hibProperties());
    return sessionFactoryBean;
}

private Properties hibProperties() {
    Properties properties = new Properties();
    properties.put(PROPERTY_NAME_HIBERNATE_DIALECT, env.getRequiredProperty(PROPERTY_NAME_HIBERNATE_DIALECT));
    properties.put(PROPERTY_NAME_HIBERNATE_SHOW_SQL, env.getRequiredProperty(PROPERTY_NAME_HIBERNATE_SHOW_SQL));
    properties.put(PROPERTY_NAME_HIBERNATE_HBM2DDL_AUTO, env.getRequiredProperty(PROPERTY_NAME_HIBERNATE_HBM2DDL_AUTO));
    return properties;
}

@Bean
public HibernateTransactionManager transactionManager() {
    HibernateTransactionManager transactionManager = new HibernateTransactionManager();
    transactionManager.setSessionFactory(sessionFactory().getObject());
    return transactionManager;
}

@Bean(name="multipartResolver")
public StandardServletMultipartResolver resolver(){
    return new StandardServletMultipartResolver();
}

@Bean
public ViewResolver getViewResolver1() {
    ResourceBundleViewResolver resolver = new ResourceBundleViewResolver();
    resolver.setOrder(1);
    resolver.setBasename("views");
    return resolver;
}

@Bean
public ViewResolver getViewResolver2() {
    InternalResourceViewResolver resolver = new InternalResourceViewResolver();
    resolver.setOrder(2);
    resolver.setPrefix("/WEB-INF/jsp/");
    resolver.setSuffix(".jsp");
    return resolver;
}

@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
    registry.addResourceHandler("/resources/**").addResourceLocations("/resources/");
}

*基本パッケージ名を保持

15
AlieneilA

以下にディレクトリ/ tmpを作成します-

C:\ Users\take\Eclipse\sts-bundle\pivotal-tc-server-developer-3.1.4.RELEASE\base-‌ instance\work\Catalina\localhost\ToolManagementSystem\WEB-INF

あなたはディレクトリを持っています-

C:\ Users\take\Eclipse\sts-bundle\pivotal-tc-server-developer-3.1.4.RELEASE\base-‌ instance\work\Catalina\localhost\ToolManagementSystem\WEB-INF\tmp

もう1つのオプションは、Tomcat構成を使用して一時ディレクトリを変更することです。または、アプリケーションプロパティを使用してこれを構成できるスプリングブートを使用できます。

ありがとう

10
farrellmr

環境の1つでは、外部プロセスが一時ディレクトリをクリーンアップするときに発生しました。そのため、アプリケーションを再起動するだけで解決しました。

2

application.propertiesファイルのserver.port値を別のポートに変更すると、機能します。

0
Osama Samy