Announcement Announcement Module
Collapse
No announcement yet.
Calling a faces managed bean with MethodInvokingTimerTaskFactoryBean...nullpointer ex Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Calling a faces managed bean with MethodInvokingTimerTaskFactoryBean...nullpointer ex

    I need to schedule a task to run every day midnight, such that it traverses the database table and find records that have not been modofied for 30 days.

    I tried calling faces managed bean and one of its method. I am using MethodInvokingTimerTaskFactoryBean. But I get null pointer exception. Application is unable to find the Service classes(which it turn call database related code)

    My application-context.xml looks like this:
    <bean id="target" class="com.view.bean.MyBean"/>
    <bean id="task" class="org.springframework.scheduling.timer.Method InvokingTimerTaskFactoryBean">
    <property name="targetObject">
    <ref local="target"/>
    </property>
    <property name="targetMethod">
    <value>myBeanMethod</value>
    </property>
    </bean>
    <bean id="timerTask" class="org.springframework.scheduling.timer.Schedu ledTimerTask">
    <property name="delay">
    <value>1000</value>
    </property>
    <property name="period">
    <value>30000</value>
    </property>
    <property name="timerTask">
    <ref local="task"/>
    </property>

    </bean>

    <bean id="timerFactory" class="org.springframework.scheduling.timer.TimerF actoryBean">
    <property name="scheduledTimerTasks">
    <list>
    <ref local="timerTask"/>
    </list>
    </property>
    </bean>

    This bean id defined in faces-managed-beans.xml

    <managed-bean>

    <managed-bean-name>myBean</managed-bean-name>
    <managed-bean-class>com.view.bean.myBean</managed-bean-class>
    <managed-bean-scope>request</managed-bean-scope>

    <managed-property>
    <property-name>serviceLocator</property-name>
    <value>#{serviceLocatorBean}</value>
    </managed-property>
    </managed-bean>

    Here is the code inside myBean...very basic ..calls the service class that in turn calls the database related code.

    public class MyBean extends BaseBean {



    public void myBeanMethod(){
    this.getServiceLocator().getMyService().getDBRecor ds();
    }



    }


    This throws a null pointer exception. It gets the service locator but throws null pointer exception when it tries to get MyService.

    Any clues?? If someone can point me in the right direction, that wud be great. I also tried calling the service class directly...still same problem.

    How can I make spring scheduler to run methods in existing ServiceImpl classes??

  • #2
    no response.....

    guys any clues or ideas????

    Comment


    • #3
      Hi,

      i think you are mixing up the faces configuration and the spring configuration. You can't access faces managed beans through spring, but you can access spring beans from faces. The configured target bean has no configured collaborator inside your applicationcontext, that is the reason for the NPE.

      Code:
      <bean id="target" class="com.view.bean.MyBean"/>
      Must be configured with its collaborators. I.e.

      Code:
      <bean id="target" class="com.view.bean.MyBean">
      <property name="serviceLocator" ref="serviceLocator"/>
      </bean>
      Where servicelocator is another bean inside your applicationcontext.

      rgds
      agim

      Comment

      Working...
      X