Results 1 to 5 of 5

Thread: Why two beans (with the same type) poin to the same reference?

  1. #1
    Join Date
    Feb 2011
    Location
    Nashville, TN
    Posts
    4

    Unhappy Why two beans (with the same type) poin to the same reference?

    So I want to have two separate manager classes managing two sets of data which have the same schema and type. I don't want to duplicate code. So as you can see I define two DAO beans, but they backed up by the same class. The DAO beans are referenced from two manager beans (also backed up by the same classes). Here comes the catch: run-time I realized that the personDao property in the personOtherManagerService bean points to the same reference as the personDao property in the personManagerService! How is that? Although the property names are the same, but they should contain two different DAO beans in theory! I don't understand, please help me, I have deadlines!
    Some relevant parts from the Spring config:

    applicationContext-dao.xml:
    ...
    Code:
        <bean id="personDao" class="org.openhie.openempi.dao.hibernate.PersonDaoHibernate">
            <property name="sessionFactory" ref="sessionFactory"/>
        </bean>
        
        <bean id="personOtherDao" class="org.openhie.openempi.dao.hibernate.PersonDaoHibernate">
            <property name="sessionFactory" ref="sessionFactory"/>
        </bean>
    ...
    applicationContext-service.xml:

    Code:
    	<bean id="context" class="org.openhie.openempi.context.Context">
    		<property name="personManagerService" ref="personManagerService" />
    		<property name="personOtherManagerService" ref="personOtherManagerService" />
    	</bean>
    
    	<bean id="personManagerService"
    		class="org.openhie.openempi.service.impl.PersonManagerServiceImpl">
    		<property name="personDao" ref="personDao" />
    	</bean>
    
    	<bean id="personOtherManagerService"
    		class="org.openhie.openempi.service.impl.PersonManagerServiceImpl">
    		<property name="personDao" ref="personOtherDao" />
    	</bean>
    Thanks in advance,
    Csaba Toth
    Last edited by ctoth; Apr 6th, 2011 at 09:31 AM. Reason: adding code tags

  2. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,632

    Default

    Please use [ code][/code ] tags when posting code, that way it remains readable ...

    Post your full configuration (also web.xml) and some code. I suspect some @Service or autowiring taking place due to your configuration.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  3. #3
    Join Date
    Feb 2011
    Location
    Nashville, TN
    Posts
    4

    Default

    Thanks Marten! I added code tags. I couldn't modify the typo in the topic title: poin -> point. All of this problem what I describe is in the core module, in the back-end, there's no UI or anything on that level. The server side of the front-end gets the services from the context bean you can see in my snippet.

    My application uses Spring for dependency injection and other stuff, but the UI is Struts and GXT/ExtJS.
    My application is based on OpenEMPI, just to get some idea:
    openempi trunk
    My application differs from OpenEMPI for example that it wants to have two PersonManagerService and PersonQueryService the way I described in my opening post. It should work as far as I can understand.
    OpenEMPI's configuration files (doesn't contain my modification, but look at my original post):
    applicationContext-dao.xml
    applicationContext-service.xml
    Last edited by ctoth; Apr 6th, 2011 at 10:08 AM.

  4. #4
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,632

    Default

    As I stated please post your configuration and code of the classes involved as I expect some duplicate/overriding configuration...
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  5. #5
    Join Date
    Feb 2011
    Location
    Nashville, TN
    Posts
    4

    Default

    I've found the cause of the problem. I modified the configuration files in the source tree, but the application reads another set of them from a separate configuration folder, and those files weren't updates.
    So what I described works

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •