title: What is the simplest way to execute a Java class every 30 seconds?
body: <p>I've been reading about java/spring/hibernate and worked trough a "dummy" examples so I told my friend to recommend something a bit harder for me, and now I'm stuck.. here is the simplest class I could think of</p>
  
  <pre><code>package spring.com.practice;
  
  public class Pitcher {
  
      private String shout;
  
      public String getShout() {
          return shout;
      }
  
      public void setShout(String shout) {
          this.shout = shout;
      }
  
      public void voice()
      {
          System.out.println(getShout());
      }
  
  }
  </code></pre>
  
  <p>What is the most simple way to print out something by calling metod <code>voice()</code> from spring beans, and do it repeadatly every 30 seconds lets say, here is what I've got so far :</p>
  
  <p>
          
          
      </p>
  
  <pre><code>&lt;bean id="simpleTrigger" class="org.springframework.scheduling.quartz.SimpleTriggerBean"&gt;
      &lt;property name="jobDetail" ref="jobSchedulerDetail" /&gt;
      &lt;property name="startDelay" value="0" /&gt;
      &lt;property name="repeatInterval" value="30" /&gt;
  &lt;/bean&gt;
  
  
  &lt;bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean"&gt;
      &lt;property name="schedulerName" value="pitcherScheduler" /&gt;
      &lt;property name="triggers"&gt;
          &lt;list&gt;
              &lt;ref bean="simpleTrigger" /&gt;
          &lt;/list&gt;
      &lt;/property&gt;
  &lt;/bean&gt;
   &lt;bean id="pitcher" class="spring.com.practice.Pitcher"&gt;
   &lt;property name="shout" value="I started executing..."&gt;&lt;/property&gt;
   &lt;/bean&gt;
  </code></pre>
  
  <p>And yes I'm trying to run this on Jboss 5, I'm building a project with maven.</p>
  
  <p>I got some suggestions and my application context now looks like :</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;beans xmlns="http://www.springframework.org/schema/beans"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xmlns:sched="http://www.springinaction.com/schema/sched"
     xsi:schemaLocation="http://www.springframework.org/schema/beans 
         http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
         http://www.springinaction.com/schema/sched
         http://www.springinaction.com/schema/sched-1.0.xsd"
         default-lazy-init="true"&gt;
  
     &lt;bean id="stuffDoer" class="spring.com.practice"&gt;
     &lt;property name="shout" value="I'm executing"/&gt;
     &lt;/bean&gt;
  
    &lt;sched:timer-job
         target-bean="stuffDoer"
         target-method="voice"
         interval="5000" 
         start-delay="1000"
         repeat-count="10" /&gt;
  
  &lt;/beans&gt;
  </code></pre>
  
  <p>Here is my web.xml :</p>
  
  <pre><code>&lt;web-app id="simple-webapp" version="2.4"
      xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
  http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"&gt;
      &lt;display-name&gt;spring app&lt;/display-name&gt;
      &lt;context-param&gt;
          &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
          &lt;param-value&gt;
              /WEB-INF/conf/applicationContext.xml
  &lt;/param-value&gt;
      &lt;/context-param&gt;
      &lt;context-param&gt;
          &lt;param-name&gt;log4jConfigLocation&lt;/param-name&gt;
          &lt;param-value&gt;/WEB-INF/log4j.properties&lt;/param-value&gt;
      &lt;/context-param&gt;
      &lt;listener&gt;
          &lt;listener-class&gt;
              org.springframework.web.util.Log4jConfigListener
  &lt;/listener-class&gt;
      &lt;/listener&gt;
      &lt;listener&gt;
          &lt;listener-class&gt;
              org.springframework.web.context.ContextLoaderListener
  &lt;/listener-class&gt;
      &lt;/listener&gt;
  &lt;/web-app&gt;
  </code></pre>
  
  <p>Now I get this exeption :</p>
  
  <pre><code>12:35:51,657 ERROR [01-SNAPSHOT]] Error configuring application listener of class org.springframework.web.context.ContextLoaderListener
  java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener
  </code></pre>
  
  <p>I didn't realize executing something like hello world every 30 sec would be this complicated</p>