Announcement Announcement Module
No announcement yet.
Calling a faces managed bean with MethodInvokingTimerTaskFactoryBean...nullpointer ex Page Title Module
Move Remove Collapse
Conversation Detail Module
  • 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 name="targetMethod">
    <bean id="timerTask" class="org.springframework.scheduling.timer.Schedu ledTimerTask">
    <property name="delay">
    <property name="period">
    <property name="timerTask">
    <ref local="task"/>


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

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




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


    • #3

      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.

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

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