Announcement Announcement Module
Collapse
No announcement yet.
[beginner] Accessing other beans Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • [beginner] Accessing other beans

    As the title says i am a beginner so excuse me if u use the wroung terminology, etc.

    This is a fragment from my bean factory definition xml:

    <beans>


    <bean id="primaryDescriptionDAO" class="com.scientia.dao.hibernate.PrimaryDescripti onDAOImpl">
    <property name="sessionFactory">
    <ref bean="bisdirSessionFactory"/>
    </property>
    </bean>


    <bean id="parseXML" class="com.scientia.busdir.xmlparsing.ParseXML">
    <property name="primaryDescriptionDAO">
    <ref local="primaryDescriptionDAO"/>
    </property>
    </bean>


    ...

    </beans>

    Bascially i have a parseXML bean and i want it to be able to access the primaryDescriptionDAO, i believe i have set this relationship up correctly in the above xml?

    What i need to know it how do i now access the primaryDescriptionDAO bean from my parseXML code? Could someone provide me with a code snippet.

  • #2
    Re: [beginner] Accessing other beans

    Originally posted by bosh
    As the title says i am a beginner so excuse me if u use the wroung terminology, etc.

    <bean id="parseXML" class="com.scientia.busdir.xmlparsing.ParseXML">
    <property name="primaryDescriptionDAO">
    <ref local="primaryDescriptionDAO"/>
    </property>
    </bean>



    Bascially i have a parseXML bean and i want it to be able to access the primaryDescriptionDAO, i believe i have set this relationship up correctly in the above xml?
    Yes

    What i need to know it how do i now access the primaryDescriptionDAO bean from my parseXML code? Could someone provide me with a code snippet.
    Just like any property you have set in the past.

    Code:
    class ParseXML&#123;
        private PrimaryDescriptionDAO dao;
    
        public void setPrimaryDescriptionDAO&#40;PrimaryDescriptionDAOImpl dao&#41;&#123;this.dao = dao;&#125;
    
       public void doSomething&#40;&#41;&#123;
                dao.removeAll&#40;&#41;;
      &#125;
    &#125;
    There is nothing magical about it.

    Comment


    • #3
      What and spring will atomatically call the setter?

      Comment


      • #4
        Originally posted by bosh
        What and spring will atomatically call the setter?
        Not automatically.. you told spring to do it:
        Code:
        <bean id="parseXML" class="com.scientia.busdir.xmlparsing.ParseXML">
           <property name="primaryDescriptionDAO">  <-- here you do it.
               <ref local="primaryDescriptionDAO"/> 
           </property>
        </bean>

        Comment

        Working...
        X