Announcement Announcement Module
Collapse
No announcement yet.
IOC basic issue : need help Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • IOC basic issue : need help

    Hi All,


    I am working on a job scheduling assignment. I am caught up in an issue relating to IOC, i am not very sure the approach i follow is a right one or not. Besides i have encountered an error.

    I have this job that should run in every 2 hrs.

    <bean id="alerts" name="due" class="com.project.util.DueCheck">
    <property name="prDao">
    <ref bean="PrDAO" />
    </property>
    <property name="pMDAO">
    <ref bean="PMDAO" />
    </property>
    <property name="nSDAO">
    <ref bean="NSDAO" />
    </property>
    <property name="csDAO">
    <ref bean="CsDAO" />
    </property>
    <property name="sDays">
    <ref bean="SDays"/>
    </property>
    </bean>

    Here sDays is a class with Util methods.

    The Job is initiated as per coded time so thats not an issue.


    My Job class com.project.util.DueCheck refers to sDays which has some utility methods written. These utility methods call prDao and fires some queries.

    My problem is for alerts i am able to do IOC fine but when control moves to the Util class. Here prDao gives a NullPointer exception. Indise the Util method


    public void dGen(int Id)
    {
    try
    {
    PR pRPojo = pRDao.findById(projectId); // NPE

    ...............
    ..............

    }
    catch(Exception e)
    {
    e.printStackTrace();
    }

    }

    Please Advice me how to correct it.


    Kind Regards,
    Leo

  • #2
    That must be because in bean "SDays", you may no be injecting the object of "PrDAO".
    Kindly check if this is being done?

    Comment


    • #3
      That must be because in bean "SDays", you may no be injecting the object of "PrDAO".
      One way to verify this would be to use the @Required annotation, for example:

      Code:
      @Required
      void setPRDao(PRDao pRDao) {
         ...
      }
      To turn this feature on remember to add the following to your bean configuration file:

      Code:
      <bean class="org.springframework.beans.factory.annotation.RequiredAnnotationBeanPostProcessor"/>
      If indeed you forgot to inject the bean then an exception is thrown.

      Comment


      • #4
        Hi riks.java and dennislee,

        Thanks alot for sharing your points. I actually wasn't aware of RequiredAnnotationBeanPostProcessor and @Required annotation. A new thing i learned.

        Actaully i did inject the prDao into SDays. But it still gives me NPE.

        Regards,
        Leo
        Last edited by bornleo26; Jun 19th, 2009, 07:03 AM.

        Comment


        • #5
          The SDays bean :

          <bean id="SDays"
          class="com.project.util.Scheck">
          <property name="pRDao">
          <ref bean="PrDAO" />
          </property>
          <property name="sTDAO">
          <ref bean="StDAO" />
          </property>
          <property name="sIDao">
          <ref bean="SiDAO" />
          </property>
          </bean>

          in


          Variables declaration ...
          ..........
          private PrDAO pr;
          .............
          .............


          project = pr.findById(Id); ---- NPE



          Am i missing some configuration setting here?


          Leo

          Comment


          • #6
            Can you post the whole configuration file?

            Comment


            • #7
              Hi dennislee,

              PFA the .txt file with the configuration contents.


              Regards,
              Leo

              Comment


              • #8
                I think the problem is in the name of your setter declaration which is not matching. Your configuration has
                Code:
                <property name="pRDao">
                So, your setter declaration must be
                Code:
                public void setPRDao(com.project.dao.ProjectDAO pRDao) {
                this.pr = pRDao;
                }
                Kindly verify.

                Comment

                Working...
                X