没有Spring bean注入的经验。
<beans:bean id="ModeService"
class="<path>Service">
<beans:property name="Mode" value="true"/>
</beans:bean>
<beans:bean id="Filter"
class="<path>.RequestFilter">
<custom-filter position="FIRST" />
</beans:bean>
如何将 ModeService bean 注入到 Filter bean 中?
好的,我在春天注射了@William 所以有:
<beans:bean id="maintenanceModeService"
class="<path>.MaintenanceService">
<beans:property name="maintenanceMode" value="true"/>
</beans:bean>
<beans:bean id="maintenanceFilter"
class="<path>.MaintenanceRequestFilter">
<custom-filter position="FIRST" />
<beans:property name="modeService" ref="maintenanceModeService"/>
</beans:bean>
在 MaintenanceService 中,我添加了 setter/getter 来调用变量:
boolean maintenanceMode;
public void setMaintenanceMode(boolean mode)
{
this.maintenanceMode = mode;
}
public boolean getMaintenanceMode()
{
return maintenanceMode;
}
并将 setter/getter 附加到 MaintenanceRequestFilter:
boolean modeService;
public void setModeService(MaintenanceService maintenanceMode)
{
this.modeService = maintenanceMode;
}
public MaintenanceService getMaintenanceMode()
{
return modeService;
}
然后在 doFilter() 中调用 modeService
但是……错了……