Announcement Announcement Module
Collapse
No announcement yet.
Multiple instances of proxied bean Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Multiple instances of proxied bean

    Hey,

    I have a small situation with AOP. I am trying to create a proxy for one of my beans which incidentally is a shared object that we are wiring to two other objects. Now, from what I have noticed, these two objects are getting two separate instances of the shared object even though the object itself has been defined with scope of singleton and the proxy being declared as singleton.

    Is there something I am missing or is this the intended behavior of spring. I am using 2.0.1

    Thanks in anticipation to all the geniuses.

  • #2
    It should have just one instance, can we see the configuration?

    Comment


    • #3
      Originally posted by mdeinum View Post
      It should have just one instance, can we see the configuration?
      Sure.... here is the relevant portions
      Code:
      <bean id="sampleInterceptor" class="com.test.SampleInterceptor"/>
      
      <bean id="nameMatchPointCut" class="org.springframework.aop.support.NameMatchMethodPointcutAdvisor">
      	<property name="mappedName">
      		<value>get</value>
      	</property>
      	<property name="advice">
      		<ref bean="sampleInterceptor"/>
      	</property>
      </bean>
      
      <bean id="sampleObjectTarget" class="com.test.SampleObjectImpl" scope="singleton" />
      	
      < bean id="sampeObect" class="org.springframework.aop.framework.ProxyFactoryBean" scope="singleton">
      	<property name="proxyInterfaces">
      		<value>com.test.SampleObject</value>
      	</property>
      	<property name="target" ref="sampleObjectTarget"/>
      	<property name="interceptorNames">
      		<list>
      			<value>nameMatchPointCut</value>
      		</list>
      	</property>
      </bean>
      The one thing I thought of was to try with
      Code:
      <bean id="sampleInterceptor" class="com.test.SampleInterceptor" scope="singleton"/>
      but did not think this would make a difference.

      Comment


      • #4
        What makes you think they are actually different instances? I would check the target to make sure you are seeing the actual object.

        Comment


        • #5
          Originally posted by karldmoore View Post
          What makes you think they are actually different instances? I would check the target to make sure you are seeing the actual object.
          I say they are different objects because when i print the object to the log... say using logger.debug(sampleObect). It gives me different references at the two locations where it is supposed to be one. Plus, when I did an obj1==obj2 check it fails. where obj1 and obj2 are the wired object at first and second locations.

          The other test I did was update the object in the first location and checked the value in the second.

          However, when I print the beanName in either of the locations it prints the name of the same target bean.

          Comment

          Working...
          X