RequestMapping으로 주석 된 메소드가있는 컨트롤러를 사용하는 스프링 mvc 응용 프로그램에 다중 파트 구성을 추가하려면 어떻게합니까?Spring MVC에서 Servlet 3.0을 사용하는 MultipartConfig
배경 :
나는 CSRF 보호를 활성화 할 등 보안 추가 : 내 스프링 설정에서 CSRF 태그를. 나는 파일 업로드에 사용되는 RequestMapping으로 주석 된 메소드가있는 컨트롤러 클래스를 가지고있다. 또한 caveat instructions을 여러 부분으로 둘러 봤으며 보안 필터 위에 multipart 필터를 추가했습니다. csrf 태그를 추가 한 후 파일을 업로드하려고 시도했을 때 누락 된 getParts() 메소드가 예외였습니다. 빠른 구글 강조 서블릿 2.5 사양을 기반으로 부두 버전을 사용하는 것이었다. 나는 jetty-maven-plugin을 8.1.14.v20131031로 업그레이드하고 다시 업로드를 시도했다. 그 결과 :
org.springframework.web.multipart.MultipartException: Could not parse multipart servlet request; nested exception is java.lang.IllegalStateException: No multipart config for servlet
at org.springframework.web.multipart.support.StandardMultipartHttpServletRequest.<init>(StandardMultipartHttpServletRequest.java:68)
at org.springframework.web.multipart.support.StandardServletMultipartResolver.resolveMultipart(StandardServletMultipartResolver.java:58)
at org.springframework.web.multipart.support.MultipartFilter.doFilterInternal(MultipartFilter.java:110)
어디에서 xml 설정을위한 멀티 파트 구성을합니까? 모든 문서에 web.xml의 특정 서블릿에 대한 서블릿 태그에 multipart-config를 추가하라는 메시지가 있습니다. 내 응용 프로그램에 대한 서블릿은 하나뿐입니다. 그래서 나는 그것에 덧붙여 같은 이슈를 얻었습니다.
<servlet>
<servlet-name>SpringDispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<multipart-config>
<location>/tmp</location>
<max-file-size>20848820</max-file-size>
<max-request-size>418018841</max-request-size>
<file-size-threshold>1048576</file-size-threshold>
</multipart-config>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/servlet-context.xml
</param-value>
</init-param>
<load-on-startup>10</load-on-startup>
</servlet>
는 또한 http://www.mkyong.com/web-development/the-web-xml-deployment-descriptor-examples/에서 공급, 서블릿 스펙의 버전 3.0을 가리 키도록 web.xml 파일의 상단에있는 스키마 위치를 업데이트.
어떤 도움이 필요합니까?
편집 : 추가 롭에 대해 다음 riles :
web.xml을
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:/spring/webapp.xml</param-value>
</context-param>
<context-param>
<param-name>spring.profiles.default</param-name>
<param-value>OracleDB,common</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<listener>
<listener-class>org.springframework.security.web.session.HttpSessionEventPublisher
</listener-class>
</listener>
<servlet>
<servlet-name>SpringDispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<multipart-config>
<location>/tmp</location>
<max-file-size>20848820</max-file-size>
<max-request-size>418018841</max-request-size>
<file-size-threshold>1048576</file-size-threshold>
</multipart-config>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/servlet-context.xml
</param-value>
</init-param>
<load-on-startup>10</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>SpringDispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<filter>
<filter-name>MultipartFilter</filter-name>
<filter-class>org.springframework.web.multipart.support.MultipartFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>MultipartFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy
</filter-class>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter>
<filter-name>sitemesh</filter-name>
<filter-class>com.opensymphony.module.sitemesh.filter.PageFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>sitemesh</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter>
<filter-name>characterEncodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<init-param>
<param-name>forceEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>characterEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter>
<filter-name>XSS</filter-name>
<filter-class>com.mycompany.CrossScriptingFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>XSS</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<session-config>
<session-timeout>10</session-timeout>
</session-config>
<resource-ref>
<description>Core Datasource</description>
<res-ref-name>jdbc/coreDataSource</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
<resource-ref>
<description>Location Datasource</description>
<res-ref-name>jdbc/locationDataSource</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
<error-page>
<!-- Missing login -->
<error-code>401</error-code>
<location>/WEB-INF/views/errorPage.jsp</location>
</error-page>
<error-page>
<!-- Forbidden directory listing -->
<error-code>403</error-code>
<location>/WEB-INF/views/errorPage.jsp</location>
</error-page>
<error-page>
<!-- Missing resource -->
<error-code>404</error-code>
<location>/WEB-INF/views/errorPageNotFound.jsp</location>
</error-page>
<error-page>
<!-- Uncaught exception -->
<error-code>500</error-code>
<location>/WEB-INF/views/errorPage.jsp</location>
</error-page>
<error-page>
<!-- Unsupported servlet method -->
<error-code>503</error-code>
<location>/WEB-INF/views/errorPage.jsp</location>
</error-page>
</web-app>
서블릿-context.xml에
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:util="http://www.springframework.org/schema/util" xmlns:security="http://www.springframework.org/schema/security"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.2.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.2.xsd">
<mvc:annotation-driven />
<mvc:resources mapping="/resources/**" location="/resources/" />
<mvc:resources mapping="/images/**" location="file:${fileSystemStore.fileSystemStorageLocation}"/>
<context:component-scan base-package="com.mycompany.console.*" />
<mvc:interceptors>
<bean class="com.mycompany.security.ChangePasswordInterceptor" />
</mvc:interceptors>
<security:global-method-security
secured-annotations="enabled" jsr250-annotations="enabled"
pre-post-annotations="enabled" proxy-target-class="true" />
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass"
value="org.springframework.web.servlet.view.JstlView" />
<property name="prefix" value="/WEB-INF/views/" />
<property name="suffix" value=".jsp" />
<property name="contentType" value="text/html;charset=UTF-8" />
</bean>
<bean id="filterMultipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name="maxUploadSize" value="100000000"/>
</bean>
<bean id="messageSource"
class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
<property name="basenames">
<list>
<value>classpath:language</value>
<value>classpath:language_additions</value>
<value>classpath:formats</value>
</list>
</property>
<property name="defaultEncoding" value="UTF-8" />
</bean>
<bean id="localeResolver" class="com.mycompany.locale.SessionLocaleResolver"/>
</beans>
에 allowCasualMultipartParsing를 사용하여 Tomcat을 사용하여 모두 완전한 작동 예를 찾을 수 있습니다. – edwardmlyte
수정, CommonsMultipartResolver를 확장 한 클래스를 사용하고 있습니다. 그러나 CMR로 직접 시도하여 동일한 오류가 발생했습니다. (별도의 문제 : csrf에 대한주의 사항 설명서는 멀티 파트 필터 매핑에서 "servlet-name"태그를 사용하도록 지시 할 때 업데이트해야하지만 예제에서는 정확한 "url-mapping"태그를 사용합니다.) – edwardmlyte
bean 이름은 같은 이름이고 루트 어플리케이션 컨텍스트에 존재합니까? 해당 구성 (파일 이름과 함께)과 전체 web.xml을 게시 할 수 있습니까? 언급 한 문서의 문제는 https://jira.spring.io/browse/SEC-2466으로 기록되었으며 3.2.1에서 수정해야합니다. 릴리스 http://docs.spring.io/spring-security를 참조하십시오. /site/docs/3.2.x/reference/htmlsingle/#csrf-multipart –