Announcement Announcement Module
Collapse
No announcement yet.
how to inject proxyfactorybean? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • how to inject proxyfactorybean?

    as title[/code]

  • #2
    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

    Comment


    • #3
      very thanks for your reply,
      and how can I add interceptor on proxyfactorybean instead of the real bean.

      Comment


      • #4
        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

        Comment


        • #5
          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?

          Comment


          • #6
            Give me a usecase. I don't know why you're tyrng to do this...

            Comment


            • #7
              this is the test code:
              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?

              Comment


              • #8
                You should just be able to use:

                <property name="target"><ref local="&amp;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?

                Comment


                • #9
                  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?

                  Comment


                  • #10
                    And I don't want to wrap the FactoryBean itself,I just use proxyfactorybean to generate proxy class instead.

                    Comment


                    • #11
                      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.

                      Comment


                      • #12
                        So I will give you the code to explain that, this is code I have shown before:
                        applicationContext.xml
                        Code:
                        <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
                        Code:
                        	<bean id="testController" class=test.controller.testController">
                        	   <property name="testbean"><ref bean="wrapbean"/></property>
                        	</bean>
                        this is the test.advisor.MixinAdvisor class code:
                        Code:
                        public class MixinAdvisor  extends DefaultIntroductionAdvisor&#123;
                           public MixinAdvisor&#40;&#41;&#123;
                        	super&#40;new testmixinImpl&#40;&#41;, testmixin.class&#41;;
                           &#125;
                        &#125;
                        so the testbean will implements testmixinImpl class after mixin.

                        this is the testInterceptor code:
                        Code:
                        public Object invoke&#40;MethodInvocation invocation&#41; throws Throwable &#123;
                        ReflectiveMethodInvocation rinvocation = &#40;ReflectiveMethodInvocation&#41;invocation;
                        if&#40;rinvocation.getThis&#40;&#41; instanceof testmixin&#41;
                        &#123;
                        //do some business code.....
                        &#125;
                        &#125;
                        I have some error will the code like above.

                        Comment


                        • #13
                          I'd just add both advisors (the interceptor as well as the mixinAdvisor) to the same ProxyFactoryBean. You should be all set then!

                          Comment


                          • #14
                            multipal proxyfactorybean use case

                            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.ProxyFact oryBean">
                            <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 .TransactionProxyFactoryBean">
                            <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

                            Comment


                            • #15
                              Originally posted by kalfen View Post
                              this is the test code:
                              Code:
                              <?xml version="1.0" encoding="UTF-8"?>
                              
                              <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
                              <beans>
                              	 <!-- <bean id="multiinterface" class="org.springframework.aop.framework.ProxyFactoryBean">
                              		<property name="proxyInterfaces">
                              		  <list>
                              			<value>com.tmd.bingo.portal.framework.InterfaceA</value>
                              			<value>com.tmd.bingo.portal.framework.InterfaceB</value>
                              			<value>com.tmd.bingo.portal.framework.InterfaceC</value>
                              		  </list>	
                              		</property>
                              		<property name="interceptorNames">
                              			<value>NameMethodPointCutAdvisor</value>
                              		</property>
                              		<property name="target">
                              			<ref bean="interfaceAimpl" />
                              			<ref bean="interfaceBimpl" />
                              			<ref bean="interfaceCimpl" />
                              		</property>
                              	</bean>-->
                              	
                              	
                              	<bean id="interfacea" class="org.springframework.aop.framework.ProxyFactoryBean">
                              		<property name="proxyInterfaces">
                              		  	<value>com.tmd.bingo.portal.framework.InterfaceA</value>
                              		</property>
                              		<!-- <property name="interceptorNames">
                              			<value>NameMethodPointCutAdvisor</value>
                              		</property>-->
                              		<property name="target">
                              			<ref bean="interfaceAimpl" />
                              		</property>
                              	</bean>
                              	
                              	<bean id="interfaceb" class="org.springframework.aop.framework.ProxyFactoryBean">
                              		<property name="proxyInterfaces">
                              		  	<value>com.tmd.bingo.portal.framework.InterfaceB</value>
                              		</property>
                              		<!-- <property name="interceptorNames">
                              			<value>NameMethodPointCutAdvisor</value>
                              		</property>-->
                              		<property name="target">
                              			<ref bean="interfaceBimpl" />
                              		</property>
                              	</bean>
                              	
                              	<bean id="interfacec" class="org.springframework.aop.framework.ProxyFactoryBean">
                              		<property name="proxyInterfaces">
                              		  	<value>com.tmd.bingo.portal.framework.InterfaceC</value>
                              		</property>
                              		<!-- <property name="interceptorNames">
                              			<value>NameMethodPointCutAdvisor</value>
                              		</property>-->
                              		<property name="target">
                              			<ref bean="interfaceCimpl" />
                              		</property>
                              	</bean>
                              	
                              	
                              	
                              	
                              	<!-- <bean id="NameMethodPointCutAdvisor"
                              		class="org.springframework.aop.support.NameMatchMethodPointcutAdvisor">
                              		<property name="mappedName">
                              			<value>dis*</value>
                              		</property>
                              		<property name="advice">
                              			<ref bean="LoggingAroundAdvice" />
                              		</property>
                              	</bean>-->
                              	
                              	<bean id="interfaceAimpl" class="com.tmd.bingo.portal.framework.InterfaceA"></bean>
                              	<bean id="interfaceBimpl" class="com.tmd.bingo.portal.framework.InterfaceB"></bean>
                              	<bean id="interfaceCimpl" class="com.tmd.bingo.portal.framework.InterfaceC"></bean>
                              	
                              	<!-- <bean id="LoggingAroundAdvice" class="com.tmd.bingo.portal.framework.LoggingAroundAdvice"></bean>-->
                              	
                              	<!-- <bean id="messagewritter" class="com.tmd.bingo.portal.framework.MessageWritter">
                              	
                              	     <constructor-arg>
                              			<value>Arabinda</value>
                              		</constructor-arg>
                              	</bean>	-->
                              		
                              		
                              	
                              </beans>
                              I got org.springframework.beans.BeanInstantiationExcepti on when I went this type of code
                              Last edited by Arabinda; Feb 26th, 2009, 05:32 AM.

                              Comment

                              Working...
                              X