Results 1 to 4 of 4

Thread: [beginner] Accessing other beans

  1. #1
    Join Date
    Aug 2005
    Location
    UK
    Posts
    2

    Default [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. #2
    Join Date
    Nov 2004
    Location
    Hilversum - The Netherlands
    Posts
    1,054

    Default Re: [beginner] Accessing other beans

    Quote 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.

  3. #3
    Join Date
    Aug 2005
    Location
    UK
    Posts
    2

    Default

    What and spring will atomatically call the setter?

  4. #4
    Join Date
    Nov 2004
    Location
    Hilversum - The Netherlands
    Posts
    1,054

    Default

    Quote 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>

Similar Threads

  1. Spring container fails with no exception
    By naor in forum Container
    Replies: 9
    Last Post: Oct 1st, 2005, 03:39 PM
  2. [beginner] About ApplicationContextAware beans
    By ccajina in forum Container
    Replies: 14
    Last Post: Aug 29th, 2005, 05:02 AM
  3. Replies: 1
    Last Post: Aug 27th, 2005, 07:50 AM
  4. Accessing methods from beans in the Flow Scope
    By jackcholt in forum Web Flow
    Replies: 4
    Last Post: May 26th, 2005, 10:28 PM
  5. Stack Overflow
    By rayho222 in forum Container
    Replies: 6
    Last Post: May 17th, 2005, 03:42 AM

Posting Permissions

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