Applying interceptors to an object in a BeanFactory
Problem:
You want to register an object into a
BeanFactory
(or ApplicationContext
) with interceptors applied to it.
Solution 1
Use Spring-AOP instead of tie for these objects. Because both of these frameworks are built on the AOP Alliance interfaces your interceptors are portable across both frameworks.
If you want to perform conditional interception you may find that it is not as easy to convert to Spring-AOP, but through the appropriate application of tie's ConditionalInterceptor this process can be simplified.
Solution 2
Use the TieFactoryBean to create your objects.
Spring supports the concept of a
FactoryBean
that can be placed into the BeanFactory
. The tie extension jar includes such a FactoryBean
for applying interceptors to beans.
<bean name="tie.stack" class="net.sf.tie.ext.spring.InterceptorList"> <property name="interceptors"> <list> <value>com.example.my.FirstInterceptor</value> <value>com.example.my.SecondInterceptor</value> </list> </property> </bean> <bean name="intercepted.bean" class="net.sf.tie.ext.spring.TieFactoryBean"> <property name="interceptionStack"><ref bean="tie.stack" /></property> <property name="interfaceName"><value>com.example.my.Interface</value></property> <property name="endPoint"> <bean class="com.example.my.Implementation" /> </property> </bean>