[英]Spring Framework filter, bean not injected
Servlet過濾器有2個條目,一個在web.xml中,另一個在Spring applicationContext.xml中
我將過濾器添加到applicationContext.xml中,因為我想將creditProcessor bean注入其中。
唯一的問題是web.xml中的條目被JBoss拾取然后使用,因此creditProcessor為null。
我是否必須使用Spring的delegingFilterProxy或類似的東西,以便我可以將東西注入bean中,或者我可以調整web.xml嗎?
web.xml中:
<filter>
<filter-name>CreditFilter</filter-name>
<filter-class>credit.filter.CreditFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>CreditFilter</filter-name>
<url-pattern>/coverage/*</url-pattern>
</filter-mapping>
Spring的applicationContext.xml中:
<bean id="creditFilter" class="credit.filter.CreditFilter" >
<property name="creditProcessor" ref="creditProcessor"/>
</bean>
你不能像這樣管理過濾彈簧。 使用您的設置,它將由spring實例化一次,並由servlet容器實例化一次。 而是使用DelegatingFilterProxy
:
<filter>
設置過濾器定義的targetBeanName
init-param以指定應該實際處理過濾的bean:
<init-param> <param-name>targetBeanName</param-name> <param-value>creditFilter</param-value> </init-param>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.