View Full Version : how to inject proxyfactorybean?
kalfen
Nov 4th, 2004, 09:21 AM
as title[/code]
Alef Arendsen
Nov 4th, 2004, 09:32 AM
If you like to reference a factorybean in your beans, you'll have to prepend the bean reference with an ampersand:
<bean id="factory" class="....FactoryBean"/>
<ref bean="&factory"/>
If you leave out the ampersand, the result of a reference to a FactoryBean will be the 'thing' the factory produces: a Proxy in case of a ProxyFactoryBean, a Map in case of a MapFactoryBean
kalfen
Nov 4th, 2004, 07:29 PM
very thanks for your reply,
and how can I add interceptor on proxyfactorybean instead of the real bean.
Alef Arendsen
Nov 5th, 2004, 04:54 AM
I honestly don't knw why you would want to add an interceptor on your proxy factory bean. You want to intercept the getBean() calls? I think it's better to extend the ProxyFactoryBean then.
You could try to add another proxyfactorybean, to proxy the proxyfactorybean, but I don't any real value here...
Alef
kalfen
Nov 5th, 2004, 07:52 AM
suppose I have a bean called businessbean, and I have add some interceptor on it via ProxyFactorybean, so when I inject into another bean, I get a proxy class. So my question is how can I add the interceptor to the proxy class? :)
Colin Sampaleanu
Nov 5th, 2004, 08:36 AM
Give me a usecase. I don't know why you're tyrng to do this...
kalfen
Nov 5th, 2004, 11:11 AM
this is the test code:
<bean id="person"
class="org.springframework.aop.framework.ProxyFactoryBean">
<property name="proxyInterfaces"><value>com.mycompany.Person</value></property>
<property name="target"><ref local="personTarget"/></property>
<property name="interceptorNames">
<list>
<value>myAdvisor</value>
<value>debugInterceptor</value>
</list>
</property>
</bean>
<bean id="wrapbean"
class="org.springframework.aop.framework.ProxyFactoryBean">
<property name="target"><ref local="person"/></property>
<property name="interceptorNames">
<list>
<value>testInterceptor</value>
</list>
</property>
</bean>
can I write xml like above?
Colin Sampaleanu
Nov 5th, 2004, 11:22 AM
You should just be able to use:
<property name="target"><ref local="&person"/></property>
but I don't know why you'd actually want to wrap the FactoryBean itself. What is the usecase? I would just add another interceptor in the first factory bean, or wrap the _result_ of it. What benefit is there to wrapping the factory itself?
kalfen
Nov 5th, 2004, 11:05 PM
hehe,
I mean that in the first proxyfactorybean, I add interceptor on the person bean, so it will generate a proxy class at the runtme to wrap person bean.
And for the second proxyfactorybean I wish to add interceptor to the proxy class generated right now , not the person bean.
And last I want to inject the second proxyed class to my webcontroller.
So if I add the two interceptor in the same proxyfactorybean, the 2 will apply to the person bean, that not I need.
So do you understand what I mean?
kalfen
Nov 5th, 2004, 11:07 PM
And I don't want to wrap the FactoryBean itself,I just use proxyfactorybean to generate proxy class instead.
:)
Alef Arendsen
Nov 6th, 2004, 05:40 AM
Well, your story tells us you want to wrap the proxy factory bean itself.
The proxy factory bean creates proxies, as the name says so you should be fine with that. Maybe you could explain your situation a bit more.
kalfen
Nov 6th, 2004, 06:32 AM
So I will give you the code to explain that, this is code I have shown before:
applicationContext.xml
<bean id="mixinbean" class="org.springframework.aop.framework.ProxyFactoryBean">
<property name="target"><ref local="testBean"/></property>
<property name="interceptorNames">
<list>
<value>mixinAdvisor</value>
</list>
</property>
</bean>
<bean id="wrapbean"
class="org.springframework.aop.framework.ProxyFactoryBean">
<property name="target"><ref local="mixinbean"/></property>
<property name="interceptorNames">
<list>
<value>testInterceptor</value>
</list>
</property>
</bean>
<bean id="mixinAdvisor"
class="test.advisor.MixinAdvisor"
singleton="false">
</bean>
<bean id="testBean" class="test.beans.TestBean">
</bean>
this is the code of app-servlet.xml
<bean id="testController" class=test.controller.testController">
<property name="testbean"><ref bean="wrapbean"/></property>
</bean>
this is the test.advisor.MixinAdvisor class code:
public class MixinAdvisor extends DefaultIntroductionAdvisor{
public MixinAdvisor(){
super(new testmixinImpl(), testmixin.class);
}
}
so the testbean will implements testmixinImpl class after mixin.
this is the testInterceptor code:
public Object invoke(MethodInvocation invocation) throws Throwable {
ReflectiveMethodInvocation rinvocation = (ReflectiveMethodInvocation)invocation;
if(rinvocation.getThis() instanceof testmixin)
{
//do some business code.....
}
}
I have some error will the code like above.
Alef Arendsen
Nov 7th, 2004, 03:49 PM
I'd just add both advisors (the interceptor as well as the mixinAdvisor) to the same ProxyFactoryBean. You should be all set then!
ajay_deoli
Jan 27th, 2005, 03:03 AM
i have the same situation. i am using the followling code
WebApplicationContext waContext = WebApplicationContextUtils.getRequiredWebApplicati onContext(servletContext);
return (BusinessServices) waContext.getBean("springBusinessService");
and this is my spring-config.xml file
<bean id="hibernateDataService" class="org.springframework.aop.framework.ProxyFactoryBean">
<property name="proxyInterfaces">
<value>DataServices</value>
</property>
<property name="interceptorNames">
<list>
<value>hibernateInterceptor</value>
//hibernate target code
<value>hibernateDataServiceTarget</value>
</list>
</property>
</bean>
<bean id="businessServiceImpl" class="BusinessService">
<property name="dataService">
<ref bean="hibernateDataService"/>
</property>
</bean>
<bean id="springBusinessService" class="org.springframework.transaction.interceptor.Transa ctionProxyFactoryBean">
<property name="transactionManager">
<ref bean="springTransactionManager"/>
</property>
<property name="target">
<ref bean="businessServiceImpl"/>
</property>
<property name="transactionAttributes">
<props>
<prop key="echo">PROPAGATION_REQUIRED</prop>
<prop key="echoUnique">PROPAGATION_REQUIRES_NEW</prop>
<prop key="test">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>
can i create the multiple ProxyFactoryBean so that i pass the differen bean to my businessServiceImpl bean.
i want to create multipal TransactionProxyFactoryBean that will be get when my application is using hibernate code, only require code will be there not all the code.
Regards
Ajay
vBulletin® v3.7.3, Copyright ©2000-2008, Jelsoft Enterprises Ltd.