0

I am facing an interesting issue. If you could enlighten me about this, I will appriciate.

Here's a scenerio; I am using Custom Filter in Spring context. I specified it as a DelegatingProxyFilter. So I made Spring context aware of this filter as a bean. I can use @Autowired annotation for ApplicationContext class and TranslationUtils class as you have seen bin the below code. But I can not use @Autowired with

CommonsMultiPartResolver(**org.springframework.web.multipart.commons.CommonsMultipartResolver**). 

Spring container can not inject it. If there is something that I have missed , Please let me know .

Code pieces Here is my filter :

@Component(value = "multipartExceptionHandlerFilter")
public class MultipartExceptionHandler extends OncePerRequestFilter {``
@Autowired // working !!
private TranslationUtils trans;

@Autowired // working !!!
private ApplicationContext applicationContext;

@Autowired // not working !!
@Qualifier("filterMultipartResolver") // also not working !!!
CommonsMultipartResolver commonsMultipartResolver;

@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)
        throws ServletException, IOException {

    //do something
        }
    }
}

filter described in web.xml :

<filter>
    <filter-name>multipartExceptionHandlerFilter</filter-name>
    <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>

<filter-mapping>
    <filter-name>multipartExceptionHandlerFilter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

Here is bean definition :

<!-- Configure the multipart resolver -->
<bean id="filterMultipartResolver"
      class="org.springframework.web.multipart.commons.CommonsMultipartResolver"
      p:maxUploadSize="52428800" p:defaultEncoding="UTF-8"/>

So what could be the problem?

Mesut Dogan
  • 572
  • 7
  • 16
  • Please show your error log ouput. – Sapikelio Nov 04 '15 at 07:31
  • Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'multipartExceptionHandlerFilter': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: – Mesut Dogan Nov 04 '15 at 07:47
  • And also it stucks in loop with this error message. – Mesut Dogan Nov 04 '15 at 07:47
  • On your filter you declare `multipartExceptionHendlerFilter` as `DelegatingFilterProxy` but on your java class it extends `OncePerRequestFilter`. This class implements `DelegatingFilterProxy`? – Sapikelio Nov 04 '15 at 07:55
  • To make spring context aware of this filter as a bean. – Mesut Dogan Nov 04 '15 at 08:05
  • Pelase refer : http://docs.spring.io/spring/docs/3.0.x/javadoc-api/org/springframework/web/filter/DelegatingFilterProxy.html Please refer : http://stackoverflow.com/questions/3645650/using-some-beans-in-filter-bean-class – Mesut Dogan Nov 04 '15 at 08:06

0 Answers0